intel_lvds.c 34 KB

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