intel_lvds.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors:
  25. * Eric Anholt <eric@anholt.net>
  26. * Dave Airlie <airlied@linux.ie>
  27. * Jesse Barnes <jesse.barnes@intel.com>
  28. */
  29. #include <acpi/button.h>
  30. #include <linux/dmi.h>
  31. #include <linux/i2c.h>
  32. #include <linux/slab.h>
  33. #include "drmP.h"
  34. #include "drm.h"
  35. #include "drm_crtc.h"
  36. #include "drm_edid.h"
  37. #include "intel_drv.h"
  38. #include "i915_drm.h"
  39. #include "i915_drv.h"
  40. #include <linux/acpi.h>
  41. /* Private structure for the integrated LVDS support */
  42. struct intel_lvds_priv {
  43. int fitting_mode;
  44. u32 pfit_control;
  45. u32 pfit_pgm_ratios;
  46. };
  47. /**
  48. * Sets the backlight level.
  49. *
  50. * \param level backlight level, from 0 to intel_lvds_get_max_backlight().
  51. */
  52. static void intel_lvds_set_backlight(struct drm_device *dev, int level)
  53. {
  54. struct drm_i915_private *dev_priv = dev->dev_private;
  55. u32 blc_pwm_ctl, reg;
  56. if (HAS_PCH_SPLIT(dev))
  57. reg = BLC_PWM_CPU_CTL;
  58. else
  59. reg = BLC_PWM_CTL;
  60. blc_pwm_ctl = I915_READ(reg) & ~BACKLIGHT_DUTY_CYCLE_MASK;
  61. I915_WRITE(reg, (blc_pwm_ctl |
  62. (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
  63. }
  64. /**
  65. * Returns the maximum level of the backlight duty cycle field.
  66. */
  67. static u32 intel_lvds_get_max_backlight(struct drm_device *dev)
  68. {
  69. struct drm_i915_private *dev_priv = dev->dev_private;
  70. u32 reg;
  71. if (HAS_PCH_SPLIT(dev))
  72. reg = BLC_PWM_PCH_CTL2;
  73. else
  74. reg = BLC_PWM_CTL;
  75. return ((I915_READ(reg) & BACKLIGHT_MODULATION_FREQ_MASK) >>
  76. BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
  77. }
  78. /**
  79. * Sets the power state for the panel.
  80. */
  81. static void intel_lvds_set_power(struct drm_device *dev, bool on)
  82. {
  83. struct drm_i915_private *dev_priv = dev->dev_private;
  84. u32 pp_status, ctl_reg, status_reg, lvds_reg;
  85. if (HAS_PCH_SPLIT(dev)) {
  86. ctl_reg = PCH_PP_CONTROL;
  87. status_reg = PCH_PP_STATUS;
  88. lvds_reg = PCH_LVDS;
  89. } else {
  90. ctl_reg = PP_CONTROL;
  91. status_reg = PP_STATUS;
  92. lvds_reg = LVDS;
  93. }
  94. if (on) {
  95. I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);
  96. POSTING_READ(lvds_reg);
  97. I915_WRITE(ctl_reg, I915_READ(ctl_reg) |
  98. POWER_TARGET_ON);
  99. do {
  100. pp_status = I915_READ(status_reg);
  101. } while ((pp_status & PP_ON) == 0);
  102. intel_lvds_set_backlight(dev, dev_priv->backlight_duty_cycle);
  103. } else {
  104. intel_lvds_set_backlight(dev, 0);
  105. I915_WRITE(ctl_reg, I915_READ(ctl_reg) &
  106. ~POWER_TARGET_ON);
  107. do {
  108. pp_status = I915_READ(status_reg);
  109. } while (pp_status & PP_ON);
  110. I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN);
  111. POSTING_READ(lvds_reg);
  112. }
  113. }
  114. static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
  115. {
  116. struct drm_device *dev = encoder->dev;
  117. if (mode == DRM_MODE_DPMS_ON)
  118. intel_lvds_set_power(dev, true);
  119. else
  120. intel_lvds_set_power(dev, false);
  121. /* XXX: We never power down the LVDS pairs. */
  122. }
  123. static void intel_lvds_save(struct drm_connector *connector)
  124. {
  125. struct drm_device *dev = connector->dev;
  126. struct drm_i915_private *dev_priv = dev->dev_private;
  127. u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg;
  128. u32 pwm_ctl_reg;
  129. if (HAS_PCH_SPLIT(dev)) {
  130. pp_on_reg = PCH_PP_ON_DELAYS;
  131. pp_off_reg = PCH_PP_OFF_DELAYS;
  132. pp_ctl_reg = PCH_PP_CONTROL;
  133. pp_div_reg = PCH_PP_DIVISOR;
  134. pwm_ctl_reg = BLC_PWM_CPU_CTL;
  135. } else {
  136. pp_on_reg = PP_ON_DELAYS;
  137. pp_off_reg = PP_OFF_DELAYS;
  138. pp_ctl_reg = PP_CONTROL;
  139. pp_div_reg = PP_DIVISOR;
  140. pwm_ctl_reg = BLC_PWM_CTL;
  141. }
  142. dev_priv->savePP_ON = I915_READ(pp_on_reg);
  143. dev_priv->savePP_OFF = I915_READ(pp_off_reg);
  144. dev_priv->savePP_CONTROL = I915_READ(pp_ctl_reg);
  145. dev_priv->savePP_DIVISOR = I915_READ(pp_div_reg);
  146. dev_priv->saveBLC_PWM_CTL = I915_READ(pwm_ctl_reg);
  147. dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
  148. BACKLIGHT_DUTY_CYCLE_MASK);
  149. /*
  150. * If the light is off at server startup, just make it full brightness
  151. */
  152. if (dev_priv->backlight_duty_cycle == 0)
  153. dev_priv->backlight_duty_cycle =
  154. intel_lvds_get_max_backlight(dev);
  155. }
  156. static void intel_lvds_restore(struct drm_connector *connector)
  157. {
  158. struct drm_device *dev = connector->dev;
  159. struct drm_i915_private *dev_priv = dev->dev_private;
  160. u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg;
  161. u32 pwm_ctl_reg;
  162. if (HAS_PCH_SPLIT(dev)) {
  163. pp_on_reg = PCH_PP_ON_DELAYS;
  164. pp_off_reg = PCH_PP_OFF_DELAYS;
  165. pp_ctl_reg = PCH_PP_CONTROL;
  166. pp_div_reg = PCH_PP_DIVISOR;
  167. pwm_ctl_reg = BLC_PWM_CPU_CTL;
  168. } else {
  169. pp_on_reg = PP_ON_DELAYS;
  170. pp_off_reg = PP_OFF_DELAYS;
  171. pp_ctl_reg = PP_CONTROL;
  172. pp_div_reg = PP_DIVISOR;
  173. pwm_ctl_reg = BLC_PWM_CTL;
  174. }
  175. I915_WRITE(pwm_ctl_reg, dev_priv->saveBLC_PWM_CTL);
  176. I915_WRITE(pp_on_reg, dev_priv->savePP_ON);
  177. I915_WRITE(pp_off_reg, dev_priv->savePP_OFF);
  178. I915_WRITE(pp_div_reg, dev_priv->savePP_DIVISOR);
  179. I915_WRITE(pp_ctl_reg, dev_priv->savePP_CONTROL);
  180. if (dev_priv->savePP_CONTROL & POWER_TARGET_ON)
  181. intel_lvds_set_power(dev, true);
  182. else
  183. intel_lvds_set_power(dev, false);
  184. }
  185. static int intel_lvds_mode_valid(struct drm_connector *connector,
  186. struct drm_display_mode *mode)
  187. {
  188. struct drm_device *dev = connector->dev;
  189. struct drm_i915_private *dev_priv = dev->dev_private;
  190. struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
  191. if (fixed_mode) {
  192. if (mode->hdisplay > fixed_mode->hdisplay)
  193. return MODE_PANEL;
  194. if (mode->vdisplay > fixed_mode->vdisplay)
  195. return MODE_PANEL;
  196. }
  197. return MODE_OK;
  198. }
  199. static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
  200. struct drm_display_mode *mode,
  201. struct drm_display_mode *adjusted_mode)
  202. {
  203. /*
  204. * float point operation is not supported . So the PANEL_RATIO_FACTOR
  205. * is defined, which can avoid the float point computation when
  206. * calculating the panel ratio.
  207. */
  208. #define PANEL_RATIO_FACTOR 8192
  209. struct drm_device *dev = encoder->dev;
  210. struct drm_i915_private *dev_priv = dev->dev_private;
  211. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  212. struct drm_encoder *tmp_encoder;
  213. struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
  214. struct intel_lvds_priv *lvds_priv = intel_encoder->dev_priv;
  215. u32 pfit_control = 0, pfit_pgm_ratios = 0;
  216. int left_border = 0, right_border = 0, top_border = 0;
  217. int bottom_border = 0;
  218. bool border = 0;
  219. int panel_ratio, desired_ratio, vert_scale, horiz_scale;
  220. int horiz_ratio, vert_ratio;
  221. u32 hsync_width, vsync_width;
  222. u32 hblank_width, vblank_width;
  223. u32 hsync_pos, vsync_pos;
  224. /* Should never happen!! */
  225. if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
  226. DRM_ERROR("Can't support LVDS on pipe A\n");
  227. return false;
  228. }
  229. /* Should never happen!! */
  230. list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
  231. if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
  232. DRM_ERROR("Can't enable LVDS and another "
  233. "encoder on the same pipe\n");
  234. return false;
  235. }
  236. }
  237. /* If we don't have a panel mode, there is nothing we can do */
  238. if (dev_priv->panel_fixed_mode == NULL)
  239. return true;
  240. /*
  241. * If we have timings from the BIOS for the panel, put them in
  242. * to the adjusted mode. The CRTC will be set up for this mode,
  243. * with the panel scaling set up to source from the H/VDisplay
  244. * of the original mode.
  245. */
  246. if (dev_priv->panel_fixed_mode != NULL) {
  247. adjusted_mode->hdisplay = dev_priv->panel_fixed_mode->hdisplay;
  248. adjusted_mode->hsync_start =
  249. dev_priv->panel_fixed_mode->hsync_start;
  250. adjusted_mode->hsync_end =
  251. dev_priv->panel_fixed_mode->hsync_end;
  252. adjusted_mode->htotal = dev_priv->panel_fixed_mode->htotal;
  253. adjusted_mode->vdisplay = dev_priv->panel_fixed_mode->vdisplay;
  254. adjusted_mode->vsync_start =
  255. dev_priv->panel_fixed_mode->vsync_start;
  256. adjusted_mode->vsync_end =
  257. dev_priv->panel_fixed_mode->vsync_end;
  258. adjusted_mode->vtotal = dev_priv->panel_fixed_mode->vtotal;
  259. adjusted_mode->clock = dev_priv->panel_fixed_mode->clock;
  260. drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
  261. }
  262. /* Make sure pre-965s set dither correctly */
  263. if (!IS_I965G(dev)) {
  264. if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
  265. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  266. }
  267. /* Native modes don't need fitting */
  268. if (adjusted_mode->hdisplay == mode->hdisplay &&
  269. adjusted_mode->vdisplay == mode->vdisplay) {
  270. pfit_pgm_ratios = 0;
  271. border = 0;
  272. goto out;
  273. }
  274. /* full screen scale for now */
  275. if (HAS_PCH_SPLIT(dev))
  276. goto out;
  277. /* 965+ wants fuzzy fitting */
  278. if (IS_I965G(dev))
  279. pfit_control |= (intel_crtc->pipe << PFIT_PIPE_SHIFT) |
  280. PFIT_FILTER_FUZZY;
  281. hsync_width = adjusted_mode->crtc_hsync_end -
  282. adjusted_mode->crtc_hsync_start;
  283. vsync_width = adjusted_mode->crtc_vsync_end -
  284. adjusted_mode->crtc_vsync_start;
  285. hblank_width = adjusted_mode->crtc_hblank_end -
  286. adjusted_mode->crtc_hblank_start;
  287. vblank_width = adjusted_mode->crtc_vblank_end -
  288. adjusted_mode->crtc_vblank_start;
  289. /*
  290. * Deal with panel fitting options. Figure out how to stretch the
  291. * image based on its aspect ratio & the current panel fitting mode.
  292. */
  293. panel_ratio = adjusted_mode->hdisplay * PANEL_RATIO_FACTOR /
  294. adjusted_mode->vdisplay;
  295. desired_ratio = mode->hdisplay * PANEL_RATIO_FACTOR /
  296. mode->vdisplay;
  297. /*
  298. * Enable automatic panel scaling for non-native modes so that they fill
  299. * the screen. Should be enabled before the pipe is enabled, according
  300. * to register description and PRM.
  301. * Change the value here to see the borders for debugging
  302. */
  303. if (!HAS_PCH_SPLIT(dev)) {
  304. I915_WRITE(BCLRPAT_A, 0);
  305. I915_WRITE(BCLRPAT_B, 0);
  306. }
  307. switch (lvds_priv->fitting_mode) {
  308. case DRM_MODE_SCALE_CENTER:
  309. /*
  310. * For centered modes, we have to calculate border widths &
  311. * heights and modify the values programmed into the CRTC.
  312. */
  313. left_border = (adjusted_mode->hdisplay - mode->hdisplay) / 2;
  314. right_border = left_border;
  315. if (mode->hdisplay & 1)
  316. right_border++;
  317. top_border = (adjusted_mode->vdisplay - mode->vdisplay) / 2;
  318. bottom_border = top_border;
  319. if (mode->vdisplay & 1)
  320. bottom_border++;
  321. /* Set active & border values */
  322. adjusted_mode->crtc_hdisplay = mode->hdisplay;
  323. /* Keep the boder be even */
  324. if (right_border & 1)
  325. right_border++;
  326. /* use the border directly instead of border minuse one */
  327. adjusted_mode->crtc_hblank_start = mode->hdisplay +
  328. right_border;
  329. /* keep the blank width constant */
  330. adjusted_mode->crtc_hblank_end =
  331. adjusted_mode->crtc_hblank_start + hblank_width;
  332. /* get the hsync pos relative to hblank start */
  333. hsync_pos = (hblank_width - hsync_width) / 2;
  334. /* keep the hsync pos be even */
  335. if (hsync_pos & 1)
  336. hsync_pos++;
  337. adjusted_mode->crtc_hsync_start =
  338. adjusted_mode->crtc_hblank_start + hsync_pos;
  339. /* keep the hsync width constant */
  340. adjusted_mode->crtc_hsync_end =
  341. adjusted_mode->crtc_hsync_start + hsync_width;
  342. adjusted_mode->crtc_vdisplay = mode->vdisplay;
  343. /* use the border instead of border minus one */
  344. adjusted_mode->crtc_vblank_start = mode->vdisplay +
  345. bottom_border;
  346. /* keep the vblank width constant */
  347. adjusted_mode->crtc_vblank_end =
  348. adjusted_mode->crtc_vblank_start + vblank_width;
  349. /* get the vsync start postion relative to vblank start */
  350. vsync_pos = (vblank_width - vsync_width) / 2;
  351. adjusted_mode->crtc_vsync_start =
  352. adjusted_mode->crtc_vblank_start + vsync_pos;
  353. /* keep the vsync width constant */
  354. adjusted_mode->crtc_vsync_end =
  355. adjusted_mode->crtc_vsync_start + vsync_width;
  356. border = 1;
  357. break;
  358. case DRM_MODE_SCALE_ASPECT:
  359. /* Scale but preserve the spect ratio */
  360. pfit_control |= PFIT_ENABLE;
  361. if (IS_I965G(dev)) {
  362. /* 965+ is easy, it does everything in hw */
  363. if (panel_ratio > desired_ratio)
  364. pfit_control |= PFIT_SCALING_PILLAR;
  365. else if (panel_ratio < desired_ratio)
  366. pfit_control |= PFIT_SCALING_LETTER;
  367. else
  368. pfit_control |= PFIT_SCALING_AUTO;
  369. } else {
  370. /*
  371. * For earlier chips we have to calculate the scaling
  372. * ratio by hand and program it into the
  373. * PFIT_PGM_RATIO register
  374. */
  375. u32 horiz_bits, vert_bits, bits = 12;
  376. horiz_ratio = mode->hdisplay * PANEL_RATIO_FACTOR/
  377. adjusted_mode->hdisplay;
  378. vert_ratio = mode->vdisplay * PANEL_RATIO_FACTOR/
  379. adjusted_mode->vdisplay;
  380. horiz_scale = adjusted_mode->hdisplay *
  381. PANEL_RATIO_FACTOR / mode->hdisplay;
  382. vert_scale = adjusted_mode->vdisplay *
  383. PANEL_RATIO_FACTOR / mode->vdisplay;
  384. /* retain aspect ratio */
  385. if (panel_ratio > desired_ratio) { /* Pillar */
  386. u32 scaled_width;
  387. scaled_width = mode->hdisplay * vert_scale /
  388. PANEL_RATIO_FACTOR;
  389. horiz_ratio = vert_ratio;
  390. pfit_control |= (VERT_AUTO_SCALE |
  391. VERT_INTERP_BILINEAR |
  392. HORIZ_INTERP_BILINEAR);
  393. /* Pillar will have left/right borders */
  394. left_border = (adjusted_mode->hdisplay -
  395. scaled_width) / 2;
  396. right_border = left_border;
  397. if (mode->hdisplay & 1) /* odd resolutions */
  398. right_border++;
  399. /* keep the border be even */
  400. if (right_border & 1)
  401. right_border++;
  402. adjusted_mode->crtc_hdisplay = scaled_width;
  403. /* use border instead of border minus one */
  404. adjusted_mode->crtc_hblank_start =
  405. scaled_width + right_border;
  406. /* keep the hblank width constant */
  407. adjusted_mode->crtc_hblank_end =
  408. adjusted_mode->crtc_hblank_start +
  409. hblank_width;
  410. /*
  411. * get the hsync start pos relative to
  412. * hblank start
  413. */
  414. hsync_pos = (hblank_width - hsync_width) / 2;
  415. /* keep the hsync_pos be even */
  416. if (hsync_pos & 1)
  417. hsync_pos++;
  418. adjusted_mode->crtc_hsync_start =
  419. adjusted_mode->crtc_hblank_start +
  420. hsync_pos;
  421. /* keept hsync width constant */
  422. adjusted_mode->crtc_hsync_end =
  423. adjusted_mode->crtc_hsync_start +
  424. hsync_width;
  425. border = 1;
  426. } else if (panel_ratio < desired_ratio) { /* letter */
  427. u32 scaled_height = mode->vdisplay *
  428. horiz_scale / PANEL_RATIO_FACTOR;
  429. vert_ratio = horiz_ratio;
  430. pfit_control |= (HORIZ_AUTO_SCALE |
  431. VERT_INTERP_BILINEAR |
  432. HORIZ_INTERP_BILINEAR);
  433. /* Letterbox will have top/bottom border */
  434. top_border = (adjusted_mode->vdisplay -
  435. scaled_height) / 2;
  436. bottom_border = top_border;
  437. if (mode->vdisplay & 1)
  438. bottom_border++;
  439. adjusted_mode->crtc_vdisplay = scaled_height;
  440. /* use border instead of border minus one */
  441. adjusted_mode->crtc_vblank_start =
  442. scaled_height + bottom_border;
  443. /* keep the vblank width constant */
  444. adjusted_mode->crtc_vblank_end =
  445. adjusted_mode->crtc_vblank_start +
  446. vblank_width;
  447. /*
  448. * get the vsync start pos relative to
  449. * vblank start
  450. */
  451. vsync_pos = (vblank_width - vsync_width) / 2;
  452. adjusted_mode->crtc_vsync_start =
  453. adjusted_mode->crtc_vblank_start +
  454. vsync_pos;
  455. /* keep the vsync width constant */
  456. adjusted_mode->crtc_vsync_end =
  457. adjusted_mode->crtc_vsync_start +
  458. vsync_width;
  459. border = 1;
  460. } else {
  461. /* Aspects match, Let hw scale both directions */
  462. pfit_control |= (VERT_AUTO_SCALE |
  463. HORIZ_AUTO_SCALE |
  464. VERT_INTERP_BILINEAR |
  465. HORIZ_INTERP_BILINEAR);
  466. }
  467. horiz_bits = (1 << bits) * horiz_ratio /
  468. PANEL_RATIO_FACTOR;
  469. vert_bits = (1 << bits) * vert_ratio /
  470. PANEL_RATIO_FACTOR;
  471. pfit_pgm_ratios =
  472. ((vert_bits << PFIT_VERT_SCALE_SHIFT) &
  473. PFIT_VERT_SCALE_MASK) |
  474. ((horiz_bits << PFIT_HORIZ_SCALE_SHIFT) &
  475. PFIT_HORIZ_SCALE_MASK);
  476. }
  477. break;
  478. case DRM_MODE_SCALE_FULLSCREEN:
  479. /*
  480. * Full scaling, even if it changes the aspect ratio.
  481. * Fortunately this is all done for us in hw.
  482. */
  483. pfit_control |= PFIT_ENABLE;
  484. if (IS_I965G(dev))
  485. pfit_control |= PFIT_SCALING_AUTO;
  486. else
  487. pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  488. VERT_INTERP_BILINEAR |
  489. HORIZ_INTERP_BILINEAR);
  490. break;
  491. default:
  492. break;
  493. }
  494. out:
  495. lvds_priv->pfit_control = pfit_control;
  496. lvds_priv->pfit_pgm_ratios = pfit_pgm_ratios;
  497. /*
  498. * When there exists the border, it means that the LVDS_BORDR
  499. * should be enabled.
  500. */
  501. if (border)
  502. dev_priv->lvds_border_bits |= LVDS_BORDER_ENABLE;
  503. else
  504. dev_priv->lvds_border_bits &= ~(LVDS_BORDER_ENABLE);
  505. /*
  506. * XXX: It would be nice to support lower refresh rates on the
  507. * panels to reduce power consumption, and perhaps match the
  508. * user's requested refresh rate.
  509. */
  510. return true;
  511. }
  512. static void intel_lvds_prepare(struct drm_encoder *encoder)
  513. {
  514. struct drm_device *dev = encoder->dev;
  515. struct drm_i915_private *dev_priv = dev->dev_private;
  516. u32 reg;
  517. if (HAS_PCH_SPLIT(dev))
  518. reg = BLC_PWM_CPU_CTL;
  519. else
  520. reg = BLC_PWM_CTL;
  521. dev_priv->saveBLC_PWM_CTL = I915_READ(reg);
  522. dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
  523. BACKLIGHT_DUTY_CYCLE_MASK);
  524. intel_lvds_set_power(dev, false);
  525. }
  526. static void intel_lvds_commit( struct drm_encoder *encoder)
  527. {
  528. struct drm_device *dev = encoder->dev;
  529. struct drm_i915_private *dev_priv = dev->dev_private;
  530. if (dev_priv->backlight_duty_cycle == 0)
  531. dev_priv->backlight_duty_cycle =
  532. intel_lvds_get_max_backlight(dev);
  533. intel_lvds_set_power(dev, true);
  534. }
  535. static void intel_lvds_mode_set(struct drm_encoder *encoder,
  536. struct drm_display_mode *mode,
  537. struct drm_display_mode *adjusted_mode)
  538. {
  539. struct drm_device *dev = encoder->dev;
  540. struct drm_i915_private *dev_priv = dev->dev_private;
  541. struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
  542. struct intel_lvds_priv *lvds_priv = intel_encoder->dev_priv;
  543. /*
  544. * The LVDS pin pair will already have been turned on in the
  545. * intel_crtc_mode_set since it has a large impact on the DPLL
  546. * settings.
  547. */
  548. if (HAS_PCH_SPLIT(dev))
  549. return;
  550. /*
  551. * Enable automatic panel scaling so that non-native modes fill the
  552. * screen. Should be enabled before the pipe is enabled, according to
  553. * register description and PRM.
  554. */
  555. I915_WRITE(PFIT_PGM_RATIOS, lvds_priv->pfit_pgm_ratios);
  556. I915_WRITE(PFIT_CONTROL, lvds_priv->pfit_control);
  557. }
  558. /**
  559. * Detect the LVDS connection.
  560. *
  561. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  562. * connected and closed means disconnected. We also send hotplug events as
  563. * needed, using lid status notification from the input layer.
  564. */
  565. static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector)
  566. {
  567. struct drm_device *dev = connector->dev;
  568. enum drm_connector_status status = connector_status_connected;
  569. /* ACPI lid methods were generally unreliable in this generation, so
  570. * don't even bother.
  571. */
  572. if (IS_GEN2(dev) || IS_GEN3(dev))
  573. return connector_status_connected;
  574. return status;
  575. }
  576. /**
  577. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  578. */
  579. static int intel_lvds_get_modes(struct drm_connector *connector)
  580. {
  581. struct drm_device *dev = connector->dev;
  582. struct intel_encoder *intel_encoder = to_intel_encoder(connector);
  583. struct drm_i915_private *dev_priv = dev->dev_private;
  584. int ret = 0;
  585. if (dev_priv->lvds_edid_good) {
  586. ret = intel_ddc_get_modes(intel_encoder);
  587. if (ret)
  588. return ret;
  589. }
  590. /* Didn't get an EDID, so
  591. * Set wide sync ranges so we get all modes
  592. * handed to valid_mode for checking
  593. */
  594. connector->display_info.min_vfreq = 0;
  595. connector->display_info.max_vfreq = 200;
  596. connector->display_info.min_hfreq = 0;
  597. connector->display_info.max_hfreq = 200;
  598. if (dev_priv->panel_fixed_mode != NULL) {
  599. struct drm_display_mode *mode;
  600. mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
  601. drm_mode_probed_add(connector, mode);
  602. return 1;
  603. }
  604. return 0;
  605. }
  606. /*
  607. * Lid events. Note the use of 'modeset_on_lid':
  608. * - we set it on lid close, and reset it on open
  609. * - we use it as a "only once" bit (ie we ignore
  610. * duplicate events where it was already properly
  611. * set/reset)
  612. * - the suspend/resume paths will also set it to
  613. * zero, since they restore the mode ("lid open").
  614. */
  615. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  616. void *unused)
  617. {
  618. struct drm_i915_private *dev_priv =
  619. container_of(nb, struct drm_i915_private, lid_notifier);
  620. struct drm_device *dev = dev_priv->dev;
  621. struct drm_connector *connector = dev_priv->int_lvds_connector;
  622. /*
  623. * check and update the status of LVDS connector after receiving
  624. * the LID nofication event.
  625. */
  626. if (connector)
  627. connector->status = connector->funcs->detect(connector);
  628. if (!acpi_lid_open()) {
  629. dev_priv->modeset_on_lid = 1;
  630. return NOTIFY_OK;
  631. }
  632. if (!dev_priv->modeset_on_lid)
  633. return NOTIFY_OK;
  634. dev_priv->modeset_on_lid = 0;
  635. mutex_lock(&dev->mode_config.mutex);
  636. drm_helper_resume_force_mode(dev);
  637. mutex_unlock(&dev->mode_config.mutex);
  638. return NOTIFY_OK;
  639. }
  640. /**
  641. * intel_lvds_destroy - unregister and free LVDS structures
  642. * @connector: connector to free
  643. *
  644. * Unregister the DDC bus for this connector then free the driver private
  645. * structure.
  646. */
  647. static void intel_lvds_destroy(struct drm_connector *connector)
  648. {
  649. struct drm_device *dev = connector->dev;
  650. struct intel_encoder *intel_encoder = to_intel_encoder(connector);
  651. struct drm_i915_private *dev_priv = dev->dev_private;
  652. if (intel_encoder->ddc_bus)
  653. intel_i2c_destroy(intel_encoder->ddc_bus);
  654. if (dev_priv->lid_notifier.notifier_call)
  655. acpi_lid_notifier_unregister(&dev_priv->lid_notifier);
  656. drm_sysfs_connector_remove(connector);
  657. drm_connector_cleanup(connector);
  658. kfree(connector);
  659. }
  660. static int intel_lvds_set_property(struct drm_connector *connector,
  661. struct drm_property *property,
  662. uint64_t value)
  663. {
  664. struct drm_device *dev = connector->dev;
  665. struct intel_encoder *intel_encoder =
  666. to_intel_encoder(connector);
  667. if (property == dev->mode_config.scaling_mode_property &&
  668. connector->encoder) {
  669. struct drm_crtc *crtc = connector->encoder->crtc;
  670. struct intel_lvds_priv *lvds_priv = intel_encoder->dev_priv;
  671. if (value == DRM_MODE_SCALE_NONE) {
  672. DRM_DEBUG_KMS("no scaling not supported\n");
  673. return 0;
  674. }
  675. if (lvds_priv->fitting_mode == value) {
  676. /* the LVDS scaling property is not changed */
  677. return 0;
  678. }
  679. lvds_priv->fitting_mode = value;
  680. if (crtc && crtc->enabled) {
  681. /*
  682. * If the CRTC is enabled, the display will be changed
  683. * according to the new panel fitting mode.
  684. */
  685. drm_crtc_helper_set_mode(crtc, &crtc->mode,
  686. crtc->x, crtc->y, crtc->fb);
  687. }
  688. }
  689. return 0;
  690. }
  691. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  692. .dpms = intel_lvds_dpms,
  693. .mode_fixup = intel_lvds_mode_fixup,
  694. .prepare = intel_lvds_prepare,
  695. .mode_set = intel_lvds_mode_set,
  696. .commit = intel_lvds_commit,
  697. };
  698. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  699. .get_modes = intel_lvds_get_modes,
  700. .mode_valid = intel_lvds_mode_valid,
  701. .best_encoder = intel_best_encoder,
  702. };
  703. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  704. .dpms = drm_helper_connector_dpms,
  705. .save = intel_lvds_save,
  706. .restore = intel_lvds_restore,
  707. .detect = intel_lvds_detect,
  708. .fill_modes = drm_helper_probe_single_connector_modes,
  709. .set_property = intel_lvds_set_property,
  710. .destroy = intel_lvds_destroy,
  711. };
  712. static void intel_lvds_enc_destroy(struct drm_encoder *encoder)
  713. {
  714. drm_encoder_cleanup(encoder);
  715. }
  716. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  717. .destroy = intel_lvds_enc_destroy,
  718. };
  719. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  720. {
  721. DRM_DEBUG_KMS("Skipping LVDS initialization for %s\n", id->ident);
  722. return 1;
  723. }
  724. /* These systems claim to have LVDS, but really don't */
  725. static const struct dmi_system_id intel_no_lvds[] = {
  726. {
  727. .callback = intel_no_lvds_dmi_callback,
  728. .ident = "Apple Mac Mini (Core series)",
  729. .matches = {
  730. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  731. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  732. },
  733. },
  734. {
  735. .callback = intel_no_lvds_dmi_callback,
  736. .ident = "Apple Mac Mini (Core 2 series)",
  737. .matches = {
  738. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  739. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  740. },
  741. },
  742. {
  743. .callback = intel_no_lvds_dmi_callback,
  744. .ident = "MSI IM-945GSE-A",
  745. .matches = {
  746. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  747. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  748. },
  749. },
  750. {
  751. .callback = intel_no_lvds_dmi_callback,
  752. .ident = "Dell Studio Hybrid",
  753. .matches = {
  754. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  755. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  756. },
  757. },
  758. {
  759. .callback = intel_no_lvds_dmi_callback,
  760. .ident = "AOpen Mini PC",
  761. .matches = {
  762. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  763. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  764. },
  765. },
  766. {
  767. .callback = intel_no_lvds_dmi_callback,
  768. .ident = "AOpen Mini PC MP915",
  769. .matches = {
  770. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  771. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  772. },
  773. },
  774. {
  775. .callback = intel_no_lvds_dmi_callback,
  776. .ident = "Aopen i945GTt-VFA",
  777. .matches = {
  778. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  779. },
  780. },
  781. {
  782. .callback = intel_no_lvds_dmi_callback,
  783. .ident = "Clientron U800",
  784. .matches = {
  785. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  786. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  787. },
  788. },
  789. { } /* terminating entry */
  790. };
  791. /**
  792. * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
  793. * @dev: drm device
  794. * @connector: LVDS connector
  795. *
  796. * Find the reduced downclock for LVDS in EDID.
  797. */
  798. static void intel_find_lvds_downclock(struct drm_device *dev,
  799. struct drm_connector *connector)
  800. {
  801. struct drm_i915_private *dev_priv = dev->dev_private;
  802. struct drm_display_mode *scan, *panel_fixed_mode;
  803. int temp_downclock;
  804. panel_fixed_mode = dev_priv->panel_fixed_mode;
  805. temp_downclock = panel_fixed_mode->clock;
  806. mutex_lock(&dev->mode_config.mutex);
  807. list_for_each_entry(scan, &connector->probed_modes, head) {
  808. /*
  809. * If one mode has the same resolution with the fixed_panel
  810. * mode while they have the different refresh rate, it means
  811. * that the reduced downclock is found for the LVDS. In such
  812. * case we can set the different FPx0/1 to dynamically select
  813. * between low and high frequency.
  814. */
  815. if (scan->hdisplay == panel_fixed_mode->hdisplay &&
  816. scan->hsync_start == panel_fixed_mode->hsync_start &&
  817. scan->hsync_end == panel_fixed_mode->hsync_end &&
  818. scan->htotal == panel_fixed_mode->htotal &&
  819. scan->vdisplay == panel_fixed_mode->vdisplay &&
  820. scan->vsync_start == panel_fixed_mode->vsync_start &&
  821. scan->vsync_end == panel_fixed_mode->vsync_end &&
  822. scan->vtotal == panel_fixed_mode->vtotal) {
  823. if (scan->clock < temp_downclock) {
  824. /*
  825. * The downclock is already found. But we
  826. * expect to find the lower downclock.
  827. */
  828. temp_downclock = scan->clock;
  829. }
  830. }
  831. }
  832. mutex_unlock(&dev->mode_config.mutex);
  833. if (temp_downclock < panel_fixed_mode->clock &&
  834. i915_lvds_downclock) {
  835. /* We found the downclock for LVDS. */
  836. dev_priv->lvds_downclock_avail = 1;
  837. dev_priv->lvds_downclock = temp_downclock;
  838. DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
  839. "Normal clock %dKhz, downclock %dKhz\n",
  840. panel_fixed_mode->clock, temp_downclock);
  841. }
  842. return;
  843. }
  844. /*
  845. * Enumerate the child dev array parsed from VBT to check whether
  846. * the LVDS is present.
  847. * If it is present, return 1.
  848. * If it is not present, return false.
  849. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  850. * Note: The addin_offset should also be checked for LVDS panel.
  851. * Only when it is non-zero, it is assumed that it is present.
  852. */
  853. static int lvds_is_present_in_vbt(struct drm_device *dev)
  854. {
  855. struct drm_i915_private *dev_priv = dev->dev_private;
  856. struct child_device_config *p_child;
  857. int i, ret;
  858. if (!dev_priv->child_dev_num)
  859. return 1;
  860. ret = 0;
  861. for (i = 0; i < dev_priv->child_dev_num; i++) {
  862. p_child = dev_priv->child_dev + i;
  863. /*
  864. * If the device type is not LFP, continue.
  865. * If the device type is 0x22, it is also regarded as LFP.
  866. */
  867. if (p_child->device_type != DEVICE_TYPE_INT_LFP &&
  868. p_child->device_type != DEVICE_TYPE_LFP)
  869. continue;
  870. /* The addin_offset should be checked. Only when it is
  871. * non-zero, it is regarded as present.
  872. */
  873. if (p_child->addin_offset) {
  874. ret = 1;
  875. break;
  876. }
  877. }
  878. return ret;
  879. }
  880. /**
  881. * intel_lvds_init - setup LVDS connectors on this device
  882. * @dev: drm device
  883. *
  884. * Create the connector, register the LVDS DDC bus, and try to figure out what
  885. * modes we can display on the LVDS panel (if present).
  886. */
  887. void intel_lvds_init(struct drm_device *dev)
  888. {
  889. struct drm_i915_private *dev_priv = dev->dev_private;
  890. struct intel_encoder *intel_encoder;
  891. struct drm_connector *connector;
  892. struct drm_encoder *encoder;
  893. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  894. struct drm_crtc *crtc;
  895. struct intel_lvds_priv *lvds_priv;
  896. u32 lvds;
  897. int pipe, gpio = GPIOC;
  898. /* Skip init on machines we know falsely report LVDS */
  899. if (dmi_check_system(intel_no_lvds))
  900. return;
  901. if (!lvds_is_present_in_vbt(dev)) {
  902. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  903. return;
  904. }
  905. if (HAS_PCH_SPLIT(dev)) {
  906. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  907. return;
  908. if (dev_priv->edp_support) {
  909. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  910. return;
  911. }
  912. gpio = PCH_GPIOC;
  913. }
  914. intel_encoder = kzalloc(sizeof(struct intel_encoder) +
  915. sizeof(struct intel_lvds_priv), GFP_KERNEL);
  916. if (!intel_encoder) {
  917. return;
  918. }
  919. connector = &intel_encoder->base;
  920. encoder = &intel_encoder->enc;
  921. drm_connector_init(dev, &intel_encoder->base, &intel_lvds_connector_funcs,
  922. DRM_MODE_CONNECTOR_LVDS);
  923. drm_encoder_init(dev, &intel_encoder->enc, &intel_lvds_enc_funcs,
  924. DRM_MODE_ENCODER_LVDS);
  925. drm_mode_connector_attach_encoder(&intel_encoder->base, &intel_encoder->enc);
  926. intel_encoder->type = INTEL_OUTPUT_LVDS;
  927. intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT);
  928. intel_encoder->crtc_mask = (1 << 1);
  929. drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
  930. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  931. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  932. connector->interlace_allowed = false;
  933. connector->doublescan_allowed = false;
  934. lvds_priv = (struct intel_lvds_priv *)(intel_encoder + 1);
  935. intel_encoder->dev_priv = lvds_priv;
  936. /* create the scaling mode property */
  937. drm_mode_create_scaling_mode_property(dev);
  938. /*
  939. * the initial panel fitting mode will be FULL_SCREEN.
  940. */
  941. drm_connector_attach_property(&intel_encoder->base,
  942. dev->mode_config.scaling_mode_property,
  943. DRM_MODE_SCALE_FULLSCREEN);
  944. lvds_priv->fitting_mode = DRM_MODE_SCALE_FULLSCREEN;
  945. /*
  946. * LVDS discovery:
  947. * 1) check for EDID on DDC
  948. * 2) check for VBT data
  949. * 3) check to see if LVDS is already on
  950. * if none of the above, no panel
  951. * 4) make sure lid is open
  952. * if closed, act like it's not there for now
  953. */
  954. /* Set up the DDC bus. */
  955. intel_encoder->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C");
  956. if (!intel_encoder->ddc_bus) {
  957. dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
  958. "failed.\n");
  959. goto failed;
  960. }
  961. /*
  962. * Attempt to get the fixed panel mode from DDC. Assume that the
  963. * preferred mode is the right one.
  964. */
  965. dev_priv->lvds_edid_good = true;
  966. if (!intel_ddc_get_modes(intel_encoder))
  967. dev_priv->lvds_edid_good = false;
  968. list_for_each_entry(scan, &connector->probed_modes, head) {
  969. mutex_lock(&dev->mode_config.mutex);
  970. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  971. dev_priv->panel_fixed_mode =
  972. drm_mode_duplicate(dev, scan);
  973. mutex_unlock(&dev->mode_config.mutex);
  974. intel_find_lvds_downclock(dev, connector);
  975. goto out;
  976. }
  977. mutex_unlock(&dev->mode_config.mutex);
  978. }
  979. /* Failed to get EDID, what about VBT? */
  980. if (dev_priv->lfp_lvds_vbt_mode) {
  981. mutex_lock(&dev->mode_config.mutex);
  982. dev_priv->panel_fixed_mode =
  983. drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  984. mutex_unlock(&dev->mode_config.mutex);
  985. if (dev_priv->panel_fixed_mode) {
  986. dev_priv->panel_fixed_mode->type |=
  987. DRM_MODE_TYPE_PREFERRED;
  988. goto out;
  989. }
  990. }
  991. /*
  992. * If we didn't get EDID, try checking if the panel is already turned
  993. * on. If so, assume that whatever is currently programmed is the
  994. * correct mode.
  995. */
  996. /* Ironlake: FIXME if still fail, not try pipe mode now */
  997. if (HAS_PCH_SPLIT(dev))
  998. goto failed;
  999. lvds = I915_READ(LVDS);
  1000. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  1001. crtc = intel_get_crtc_from_pipe(dev, pipe);
  1002. if (crtc && (lvds & LVDS_PORT_EN)) {
  1003. dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc);
  1004. if (dev_priv->panel_fixed_mode) {
  1005. dev_priv->panel_fixed_mode->type |=
  1006. DRM_MODE_TYPE_PREFERRED;
  1007. goto out;
  1008. }
  1009. }
  1010. /* If we still don't have a mode after all that, give up. */
  1011. if (!dev_priv->panel_fixed_mode)
  1012. goto failed;
  1013. out:
  1014. if (HAS_PCH_SPLIT(dev)) {
  1015. u32 pwm;
  1016. /* make sure PWM is enabled */
  1017. pwm = I915_READ(BLC_PWM_CPU_CTL2);
  1018. pwm |= (PWM_ENABLE | PWM_PIPE_B);
  1019. I915_WRITE(BLC_PWM_CPU_CTL2, pwm);
  1020. pwm = I915_READ(BLC_PWM_PCH_CTL1);
  1021. pwm |= PWM_PCH_ENABLE;
  1022. I915_WRITE(BLC_PWM_PCH_CTL1, pwm);
  1023. }
  1024. dev_priv->lid_notifier.notifier_call = intel_lid_notify;
  1025. if (acpi_lid_notifier_register(&dev_priv->lid_notifier)) {
  1026. DRM_DEBUG_KMS("lid notifier registration failed\n");
  1027. dev_priv->lid_notifier.notifier_call = NULL;
  1028. }
  1029. /* keep the LVDS connector */
  1030. dev_priv->int_lvds_connector = connector;
  1031. drm_sysfs_connector_add(connector);
  1032. return;
  1033. failed:
  1034. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  1035. if (intel_encoder->ddc_bus)
  1036. intel_i2c_destroy(intel_encoder->ddc_bus);
  1037. drm_connector_cleanup(connector);
  1038. drm_encoder_cleanup(encoder);
  1039. kfree(intel_encoder);
  1040. }