intel_lvds.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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 <drm/drmP.h>
  34. #include <drm/drm_crtc.h>
  35. #include <drm/drm_edid.h>
  36. #include "intel_drv.h"
  37. #include <drm/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_connector {
  42. struct intel_connector base;
  43. struct notifier_block lid_notifier;
  44. };
  45. struct intel_lvds_encoder {
  46. struct intel_encoder base;
  47. u32 pfit_control;
  48. u32 pfit_pgm_ratios;
  49. bool is_dual_link;
  50. u32 reg;
  51. struct intel_lvds_connector *attached_connector;
  52. };
  53. static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
  54. {
  55. return container_of(encoder, struct intel_lvds_encoder, base.base);
  56. }
  57. static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
  58. {
  59. return container_of(connector, struct intel_lvds_connector, base.base);
  60. }
  61. static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
  62. enum pipe *pipe)
  63. {
  64. struct drm_device *dev = encoder->base.dev;
  65. struct drm_i915_private *dev_priv = dev->dev_private;
  66. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  67. u32 tmp;
  68. tmp = I915_READ(lvds_encoder->reg);
  69. if (!(tmp & LVDS_PORT_EN))
  70. return false;
  71. if (HAS_PCH_CPT(dev))
  72. *pipe = PORT_TO_PIPE_CPT(tmp);
  73. else
  74. *pipe = PORT_TO_PIPE(tmp);
  75. return true;
  76. }
  77. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  78. * This is an exception to the general rule that mode_set doesn't turn
  79. * things on.
  80. */
  81. static void intel_pre_pll_enable_lvds(struct intel_encoder *encoder)
  82. {
  83. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  84. struct drm_device *dev = encoder->base.dev;
  85. struct drm_i915_private *dev_priv = dev->dev_private;
  86. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  87. struct drm_display_mode *fixed_mode =
  88. lvds_encoder->attached_connector->base.panel.fixed_mode;
  89. int pipe = intel_crtc->pipe;
  90. u32 temp;
  91. temp = I915_READ(lvds_encoder->reg);
  92. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  93. if (HAS_PCH_CPT(dev)) {
  94. temp &= ~PORT_TRANS_SEL_MASK;
  95. temp |= PORT_TRANS_SEL_CPT(pipe);
  96. } else {
  97. if (pipe == 1) {
  98. temp |= LVDS_PIPEB_SELECT;
  99. } else {
  100. temp &= ~LVDS_PIPEB_SELECT;
  101. }
  102. }
  103. /* set the corresponsding LVDS_BORDER bit */
  104. temp |= dev_priv->lvds_border_bits;
  105. /* Set the B0-B3 data pairs corresponding to whether we're going to
  106. * set the DPLLs for dual-channel mode or not.
  107. */
  108. if (lvds_encoder->is_dual_link)
  109. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  110. else
  111. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  112. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  113. * appropriately here, but we need to look more thoroughly into how
  114. * panels behave in the two modes.
  115. */
  116. /* Set the dithering flag on LVDS as needed, note that there is no
  117. * special lvds dither control bit on pch-split platforms, dithering is
  118. * only controlled through the PIPECONF reg. */
  119. if (INTEL_INFO(dev)->gen == 4) {
  120. if (dev_priv->lvds_dither)
  121. temp |= LVDS_ENABLE_DITHER;
  122. else
  123. temp &= ~LVDS_ENABLE_DITHER;
  124. }
  125. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  126. if (fixed_mode->flags & DRM_MODE_FLAG_NHSYNC)
  127. temp |= LVDS_HSYNC_POLARITY;
  128. if (fixed_mode->flags & DRM_MODE_FLAG_NVSYNC)
  129. temp |= LVDS_VSYNC_POLARITY;
  130. I915_WRITE(lvds_encoder->reg, temp);
  131. }
  132. static void intel_pre_enable_lvds(struct intel_encoder *encoder)
  133. {
  134. struct drm_device *dev = encoder->base.dev;
  135. struct intel_lvds_encoder *enc = to_lvds_encoder(&encoder->base);
  136. struct drm_i915_private *dev_priv = dev->dev_private;
  137. if (HAS_PCH_SPLIT(dev) || !enc->pfit_control)
  138. return;
  139. /*
  140. * Enable automatic panel scaling so that non-native modes
  141. * fill the screen. The panel fitter should only be
  142. * adjusted whilst the pipe is disabled, according to
  143. * register description and PRM.
  144. */
  145. DRM_DEBUG_KMS("applying panel-fitter: %x, %x\n",
  146. enc->pfit_control,
  147. enc->pfit_pgm_ratios);
  148. I915_WRITE(PFIT_PGM_RATIOS, enc->pfit_pgm_ratios);
  149. I915_WRITE(PFIT_CONTROL, enc->pfit_control);
  150. }
  151. /**
  152. * Sets the power state for the panel.
  153. */
  154. static void intel_enable_lvds(struct intel_encoder *encoder)
  155. {
  156. struct drm_device *dev = encoder->base.dev;
  157. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  158. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  159. struct drm_i915_private *dev_priv = dev->dev_private;
  160. u32 ctl_reg, stat_reg;
  161. if (HAS_PCH_SPLIT(dev)) {
  162. ctl_reg = PCH_PP_CONTROL;
  163. stat_reg = PCH_PP_STATUS;
  164. } else {
  165. ctl_reg = PP_CONTROL;
  166. stat_reg = PP_STATUS;
  167. }
  168. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
  169. I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
  170. POSTING_READ(lvds_encoder->reg);
  171. if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
  172. DRM_ERROR("timed out waiting for panel to power on\n");
  173. intel_panel_enable_backlight(dev, intel_crtc->pipe);
  174. }
  175. static void intel_disable_lvds(struct intel_encoder *encoder)
  176. {
  177. struct drm_device *dev = encoder->base.dev;
  178. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  179. struct drm_i915_private *dev_priv = dev->dev_private;
  180. u32 ctl_reg, stat_reg;
  181. if (HAS_PCH_SPLIT(dev)) {
  182. ctl_reg = PCH_PP_CONTROL;
  183. stat_reg = PCH_PP_STATUS;
  184. } else {
  185. ctl_reg = PP_CONTROL;
  186. stat_reg = PP_STATUS;
  187. }
  188. intel_panel_disable_backlight(dev);
  189. I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
  190. if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
  191. DRM_ERROR("timed out waiting for panel to power off\n");
  192. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
  193. POSTING_READ(lvds_encoder->reg);
  194. }
  195. static int intel_lvds_mode_valid(struct drm_connector *connector,
  196. struct drm_display_mode *mode)
  197. {
  198. struct intel_connector *intel_connector = to_intel_connector(connector);
  199. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  200. if (mode->hdisplay > fixed_mode->hdisplay)
  201. return MODE_PANEL;
  202. if (mode->vdisplay > fixed_mode->vdisplay)
  203. return MODE_PANEL;
  204. return MODE_OK;
  205. }
  206. static void
  207. centre_horizontally(struct drm_display_mode *mode,
  208. int width)
  209. {
  210. u32 border, sync_pos, blank_width, sync_width;
  211. /* keep the hsync and hblank widths constant */
  212. sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
  213. blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
  214. sync_pos = (blank_width - sync_width + 1) / 2;
  215. border = (mode->hdisplay - width + 1) / 2;
  216. border += border & 1; /* make the border even */
  217. mode->crtc_hdisplay = width;
  218. mode->crtc_hblank_start = width + border;
  219. mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
  220. mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
  221. mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
  222. }
  223. static void
  224. centre_vertically(struct drm_display_mode *mode,
  225. int height)
  226. {
  227. u32 border, sync_pos, blank_width, sync_width;
  228. /* keep the vsync and vblank widths constant */
  229. sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
  230. blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
  231. sync_pos = (blank_width - sync_width + 1) / 2;
  232. border = (mode->vdisplay - height + 1) / 2;
  233. mode->crtc_vdisplay = height;
  234. mode->crtc_vblank_start = height + border;
  235. mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
  236. mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
  237. mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
  238. }
  239. static inline u32 panel_fitter_scaling(u32 source, u32 target)
  240. {
  241. /*
  242. * Floating point operation is not supported. So the FACTOR
  243. * is defined, which can avoid the floating point computation
  244. * when calculating the panel ratio.
  245. */
  246. #define ACCURACY 12
  247. #define FACTOR (1 << ACCURACY)
  248. u32 ratio = source * FACTOR / target;
  249. return (FACTOR * ratio + FACTOR/2) / FACTOR;
  250. }
  251. static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
  252. struct intel_crtc_config *pipe_config)
  253. {
  254. struct drm_device *dev = intel_encoder->base.dev;
  255. struct drm_i915_private *dev_priv = dev->dev_private;
  256. struct intel_lvds_encoder *lvds_encoder =
  257. to_lvds_encoder(&intel_encoder->base);
  258. struct intel_connector *intel_connector =
  259. &lvds_encoder->attached_connector->base;
  260. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  261. struct drm_display_mode *mode = &pipe_config->requested_mode;
  262. struct intel_crtc *intel_crtc = lvds_encoder->base.new_crtc;
  263. u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
  264. unsigned int lvds_bpp;
  265. int pipe;
  266. /* Should never happen!! */
  267. if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
  268. DRM_ERROR("Can't support LVDS on pipe A\n");
  269. return false;
  270. }
  271. if (intel_encoder_check_is_cloned(&lvds_encoder->base))
  272. return false;
  273. if ((I915_READ(lvds_encoder->reg) & LVDS_A3_POWER_MASK) ==
  274. LVDS_A3_POWER_UP)
  275. lvds_bpp = 8*3;
  276. else
  277. lvds_bpp = 6*3;
  278. if (lvds_bpp != pipe_config->pipe_bpp) {
  279. DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
  280. pipe_config->pipe_bpp, lvds_bpp);
  281. pipe_config->pipe_bpp = lvds_bpp;
  282. }
  283. /*
  284. * We have timings from the BIOS for the panel, put them in
  285. * to the adjusted mode. The CRTC will be set up for this mode,
  286. * with the panel scaling set up to source from the H/VDisplay
  287. * of the original mode.
  288. */
  289. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  290. adjusted_mode);
  291. if (HAS_PCH_SPLIT(dev)) {
  292. pipe_config->has_pch_encoder = true;
  293. intel_pch_panel_fitting(dev,
  294. intel_connector->panel.fitting_mode,
  295. mode, adjusted_mode);
  296. return true;
  297. }
  298. /* Native modes don't need fitting */
  299. if (adjusted_mode->hdisplay == mode->hdisplay &&
  300. adjusted_mode->vdisplay == mode->vdisplay)
  301. goto out;
  302. /* 965+ wants fuzzy fitting */
  303. if (INTEL_INFO(dev)->gen >= 4)
  304. pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
  305. PFIT_FILTER_FUZZY);
  306. /*
  307. * Enable automatic panel scaling for non-native modes so that they fill
  308. * the screen. Should be enabled before the pipe is enabled, according
  309. * to register description and PRM.
  310. * Change the value here to see the borders for debugging
  311. */
  312. for_each_pipe(pipe)
  313. I915_WRITE(BCLRPAT(pipe), 0);
  314. drm_mode_set_crtcinfo(adjusted_mode, 0);
  315. pipe_config->timings_set = true;
  316. switch (intel_connector->panel.fitting_mode) {
  317. case DRM_MODE_SCALE_CENTER:
  318. /*
  319. * For centered modes, we have to calculate border widths &
  320. * heights and modify the values programmed into the CRTC.
  321. */
  322. centre_horizontally(adjusted_mode, mode->hdisplay);
  323. centre_vertically(adjusted_mode, mode->vdisplay);
  324. border = LVDS_BORDER_ENABLE;
  325. break;
  326. case DRM_MODE_SCALE_ASPECT:
  327. /* Scale but preserve the aspect ratio */
  328. if (INTEL_INFO(dev)->gen >= 4) {
  329. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  330. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  331. /* 965+ is easy, it does everything in hw */
  332. if (scaled_width > scaled_height)
  333. pfit_control |= PFIT_ENABLE | PFIT_SCALING_PILLAR;
  334. else if (scaled_width < scaled_height)
  335. pfit_control |= PFIT_ENABLE | PFIT_SCALING_LETTER;
  336. else if (adjusted_mode->hdisplay != mode->hdisplay)
  337. pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
  338. } else {
  339. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  340. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  341. /*
  342. * For earlier chips we have to calculate the scaling
  343. * ratio by hand and program it into the
  344. * PFIT_PGM_RATIO register
  345. */
  346. if (scaled_width > scaled_height) { /* pillar */
  347. centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
  348. border = LVDS_BORDER_ENABLE;
  349. if (mode->vdisplay != adjusted_mode->vdisplay) {
  350. u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
  351. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  352. bits << PFIT_VERT_SCALE_SHIFT);
  353. pfit_control |= (PFIT_ENABLE |
  354. VERT_INTERP_BILINEAR |
  355. HORIZ_INTERP_BILINEAR);
  356. }
  357. } else if (scaled_width < scaled_height) { /* letter */
  358. centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
  359. border = LVDS_BORDER_ENABLE;
  360. if (mode->hdisplay != adjusted_mode->hdisplay) {
  361. u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
  362. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  363. bits << PFIT_VERT_SCALE_SHIFT);
  364. pfit_control |= (PFIT_ENABLE |
  365. VERT_INTERP_BILINEAR |
  366. HORIZ_INTERP_BILINEAR);
  367. }
  368. } else
  369. /* Aspects match, Let hw scale both directions */
  370. pfit_control |= (PFIT_ENABLE |
  371. VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  372. VERT_INTERP_BILINEAR |
  373. HORIZ_INTERP_BILINEAR);
  374. }
  375. break;
  376. case DRM_MODE_SCALE_FULLSCREEN:
  377. /*
  378. * Full scaling, even if it changes the aspect ratio.
  379. * Fortunately this is all done for us in hw.
  380. */
  381. if (mode->vdisplay != adjusted_mode->vdisplay ||
  382. mode->hdisplay != adjusted_mode->hdisplay) {
  383. pfit_control |= PFIT_ENABLE;
  384. if (INTEL_INFO(dev)->gen >= 4)
  385. pfit_control |= PFIT_SCALING_AUTO;
  386. else
  387. pfit_control |= (VERT_AUTO_SCALE |
  388. VERT_INTERP_BILINEAR |
  389. HORIZ_AUTO_SCALE |
  390. HORIZ_INTERP_BILINEAR);
  391. }
  392. break;
  393. default:
  394. break;
  395. }
  396. out:
  397. /* If not enabling scaling, be consistent and always use 0. */
  398. if ((pfit_control & PFIT_ENABLE) == 0) {
  399. pfit_control = 0;
  400. pfit_pgm_ratios = 0;
  401. }
  402. /* Make sure pre-965 set dither correctly */
  403. if (INTEL_INFO(dev)->gen < 4 && dev_priv->lvds_dither)
  404. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  405. if (pfit_control != lvds_encoder->pfit_control ||
  406. pfit_pgm_ratios != lvds_encoder->pfit_pgm_ratios) {
  407. lvds_encoder->pfit_control = pfit_control;
  408. lvds_encoder->pfit_pgm_ratios = pfit_pgm_ratios;
  409. }
  410. dev_priv->lvds_border_bits = border;
  411. /*
  412. * XXX: It would be nice to support lower refresh rates on the
  413. * panels to reduce power consumption, and perhaps match the
  414. * user's requested refresh rate.
  415. */
  416. return true;
  417. }
  418. static void intel_lvds_mode_set(struct drm_encoder *encoder,
  419. struct drm_display_mode *mode,
  420. struct drm_display_mode *adjusted_mode)
  421. {
  422. /*
  423. * The LVDS pin pair will already have been turned on in the
  424. * intel_crtc_mode_set since it has a large impact on the DPLL
  425. * settings.
  426. */
  427. }
  428. /**
  429. * Detect the LVDS connection.
  430. *
  431. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  432. * connected and closed means disconnected. We also send hotplug events as
  433. * needed, using lid status notification from the input layer.
  434. */
  435. static enum drm_connector_status
  436. intel_lvds_detect(struct drm_connector *connector, bool force)
  437. {
  438. struct drm_device *dev = connector->dev;
  439. enum drm_connector_status status;
  440. status = intel_panel_detect(dev);
  441. if (status != connector_status_unknown)
  442. return status;
  443. return connector_status_connected;
  444. }
  445. /**
  446. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  447. */
  448. static int intel_lvds_get_modes(struct drm_connector *connector)
  449. {
  450. struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
  451. struct drm_device *dev = connector->dev;
  452. struct drm_display_mode *mode;
  453. /* use cached edid if we have one */
  454. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  455. return drm_add_edid_modes(connector, lvds_connector->base.edid);
  456. mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
  457. if (mode == NULL)
  458. return 0;
  459. drm_mode_probed_add(connector, mode);
  460. return 1;
  461. }
  462. static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
  463. {
  464. DRM_INFO("Skipping forced modeset for %s\n", id->ident);
  465. return 1;
  466. }
  467. /* The GPU hangs up on these systems if modeset is performed on LID open */
  468. static const struct dmi_system_id intel_no_modeset_on_lid[] = {
  469. {
  470. .callback = intel_no_modeset_on_lid_dmi_callback,
  471. .ident = "Toshiba Tecra A11",
  472. .matches = {
  473. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  474. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
  475. },
  476. },
  477. { } /* terminating entry */
  478. };
  479. /*
  480. * Lid events. Note the use of 'modeset':
  481. * - we set it to MODESET_ON_LID_OPEN on lid close,
  482. * and set it to MODESET_DONE on open
  483. * - we use it as a "only once" bit (ie we ignore
  484. * duplicate events where it was already properly set)
  485. * - the suspend/resume paths will set it to
  486. * MODESET_SUSPENDED and ignore the lid open event,
  487. * because they restore the mode ("lid open").
  488. */
  489. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  490. void *unused)
  491. {
  492. struct intel_lvds_connector *lvds_connector =
  493. container_of(nb, struct intel_lvds_connector, lid_notifier);
  494. struct drm_connector *connector = &lvds_connector->base.base;
  495. struct drm_device *dev = connector->dev;
  496. struct drm_i915_private *dev_priv = dev->dev_private;
  497. if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
  498. return NOTIFY_OK;
  499. mutex_lock(&dev_priv->modeset_restore_lock);
  500. if (dev_priv->modeset_restore == MODESET_SUSPENDED)
  501. goto exit;
  502. /*
  503. * check and update the status of LVDS connector after receiving
  504. * the LID nofication event.
  505. */
  506. connector->status = connector->funcs->detect(connector, false);
  507. /* Don't force modeset on machines where it causes a GPU lockup */
  508. if (dmi_check_system(intel_no_modeset_on_lid))
  509. goto exit;
  510. if (!acpi_lid_open()) {
  511. /* do modeset on next lid open event */
  512. dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
  513. goto exit;
  514. }
  515. if (dev_priv->modeset_restore == MODESET_DONE)
  516. goto exit;
  517. drm_modeset_lock_all(dev);
  518. intel_modeset_setup_hw_state(dev, true);
  519. drm_modeset_unlock_all(dev);
  520. dev_priv->modeset_restore = MODESET_DONE;
  521. exit:
  522. mutex_unlock(&dev_priv->modeset_restore_lock);
  523. return NOTIFY_OK;
  524. }
  525. /**
  526. * intel_lvds_destroy - unregister and free LVDS structures
  527. * @connector: connector to free
  528. *
  529. * Unregister the DDC bus for this connector then free the driver private
  530. * structure.
  531. */
  532. static void intel_lvds_destroy(struct drm_connector *connector)
  533. {
  534. struct intel_lvds_connector *lvds_connector =
  535. to_lvds_connector(connector);
  536. if (lvds_connector->lid_notifier.notifier_call)
  537. acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
  538. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  539. kfree(lvds_connector->base.edid);
  540. intel_panel_fini(&lvds_connector->base.panel);
  541. drm_sysfs_connector_remove(connector);
  542. drm_connector_cleanup(connector);
  543. kfree(connector);
  544. }
  545. static int intel_lvds_set_property(struct drm_connector *connector,
  546. struct drm_property *property,
  547. uint64_t value)
  548. {
  549. struct intel_connector *intel_connector = to_intel_connector(connector);
  550. struct drm_device *dev = connector->dev;
  551. if (property == dev->mode_config.scaling_mode_property) {
  552. struct drm_crtc *crtc;
  553. if (value == DRM_MODE_SCALE_NONE) {
  554. DRM_DEBUG_KMS("no scaling not supported\n");
  555. return -EINVAL;
  556. }
  557. if (intel_connector->panel.fitting_mode == value) {
  558. /* the LVDS scaling property is not changed */
  559. return 0;
  560. }
  561. intel_connector->panel.fitting_mode = value;
  562. crtc = intel_attached_encoder(connector)->base.crtc;
  563. if (crtc && crtc->enabled) {
  564. /*
  565. * If the CRTC is enabled, the display will be changed
  566. * according to the new panel fitting mode.
  567. */
  568. intel_crtc_restore_mode(crtc);
  569. }
  570. }
  571. return 0;
  572. }
  573. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  574. .mode_set = intel_lvds_mode_set,
  575. };
  576. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  577. .get_modes = intel_lvds_get_modes,
  578. .mode_valid = intel_lvds_mode_valid,
  579. .best_encoder = intel_best_encoder,
  580. };
  581. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  582. .dpms = intel_connector_dpms,
  583. .detect = intel_lvds_detect,
  584. .fill_modes = drm_helper_probe_single_connector_modes,
  585. .set_property = intel_lvds_set_property,
  586. .destroy = intel_lvds_destroy,
  587. };
  588. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  589. .destroy = intel_encoder_destroy,
  590. };
  591. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  592. {
  593. DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
  594. return 1;
  595. }
  596. /* These systems claim to have LVDS, but really don't */
  597. static const struct dmi_system_id intel_no_lvds[] = {
  598. {
  599. .callback = intel_no_lvds_dmi_callback,
  600. .ident = "Apple Mac Mini (Core series)",
  601. .matches = {
  602. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  603. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  604. },
  605. },
  606. {
  607. .callback = intel_no_lvds_dmi_callback,
  608. .ident = "Apple Mac Mini (Core 2 series)",
  609. .matches = {
  610. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  611. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  612. },
  613. },
  614. {
  615. .callback = intel_no_lvds_dmi_callback,
  616. .ident = "MSI IM-945GSE-A",
  617. .matches = {
  618. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  619. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  620. },
  621. },
  622. {
  623. .callback = intel_no_lvds_dmi_callback,
  624. .ident = "Dell Studio Hybrid",
  625. .matches = {
  626. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  627. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  628. },
  629. },
  630. {
  631. .callback = intel_no_lvds_dmi_callback,
  632. .ident = "Dell OptiPlex FX170",
  633. .matches = {
  634. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  635. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
  636. },
  637. },
  638. {
  639. .callback = intel_no_lvds_dmi_callback,
  640. .ident = "AOpen Mini PC",
  641. .matches = {
  642. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  643. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  644. },
  645. },
  646. {
  647. .callback = intel_no_lvds_dmi_callback,
  648. .ident = "AOpen Mini PC MP915",
  649. .matches = {
  650. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  651. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  652. },
  653. },
  654. {
  655. .callback = intel_no_lvds_dmi_callback,
  656. .ident = "AOpen i915GMm-HFS",
  657. .matches = {
  658. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  659. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  660. },
  661. },
  662. {
  663. .callback = intel_no_lvds_dmi_callback,
  664. .ident = "AOpen i45GMx-I",
  665. .matches = {
  666. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  667. DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
  668. },
  669. },
  670. {
  671. .callback = intel_no_lvds_dmi_callback,
  672. .ident = "Aopen i945GTt-VFA",
  673. .matches = {
  674. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  675. },
  676. },
  677. {
  678. .callback = intel_no_lvds_dmi_callback,
  679. .ident = "Clientron U800",
  680. .matches = {
  681. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  682. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  683. },
  684. },
  685. {
  686. .callback = intel_no_lvds_dmi_callback,
  687. .ident = "Clientron E830",
  688. .matches = {
  689. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  690. DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
  691. },
  692. },
  693. {
  694. .callback = intel_no_lvds_dmi_callback,
  695. .ident = "Asus EeeBox PC EB1007",
  696. .matches = {
  697. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  698. DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
  699. },
  700. },
  701. {
  702. .callback = intel_no_lvds_dmi_callback,
  703. .ident = "Asus AT5NM10T-I",
  704. .matches = {
  705. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  706. DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
  707. },
  708. },
  709. {
  710. .callback = intel_no_lvds_dmi_callback,
  711. .ident = "Hewlett-Packard HP t5740",
  712. .matches = {
  713. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  714. DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
  715. },
  716. },
  717. {
  718. .callback = intel_no_lvds_dmi_callback,
  719. .ident = "Hewlett-Packard t5745",
  720. .matches = {
  721. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  722. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
  723. },
  724. },
  725. {
  726. .callback = intel_no_lvds_dmi_callback,
  727. .ident = "Hewlett-Packard st5747",
  728. .matches = {
  729. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  730. DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
  731. },
  732. },
  733. {
  734. .callback = intel_no_lvds_dmi_callback,
  735. .ident = "MSI Wind Box DC500",
  736. .matches = {
  737. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  738. DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
  739. },
  740. },
  741. {
  742. .callback = intel_no_lvds_dmi_callback,
  743. .ident = "Gigabyte GA-D525TUD",
  744. .matches = {
  745. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  746. DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
  747. },
  748. },
  749. {
  750. .callback = intel_no_lvds_dmi_callback,
  751. .ident = "Supermicro X7SPA-H",
  752. .matches = {
  753. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  754. DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
  755. },
  756. },
  757. {
  758. .callback = intel_no_lvds_dmi_callback,
  759. .ident = "Fujitsu Esprimo Q900",
  760. .matches = {
  761. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  762. DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
  763. },
  764. },
  765. {
  766. .callback = intel_no_lvds_dmi_callback,
  767. .ident = "Intel D510MO",
  768. .matches = {
  769. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  770. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
  771. },
  772. },
  773. {
  774. .callback = intel_no_lvds_dmi_callback,
  775. .ident = "Intel D525MW",
  776. .matches = {
  777. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  778. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
  779. },
  780. },
  781. { } /* terminating entry */
  782. };
  783. /**
  784. * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
  785. * @dev: drm device
  786. * @connector: LVDS connector
  787. *
  788. * Find the reduced downclock for LVDS in EDID.
  789. */
  790. static void intel_find_lvds_downclock(struct drm_device *dev,
  791. struct drm_display_mode *fixed_mode,
  792. struct drm_connector *connector)
  793. {
  794. struct drm_i915_private *dev_priv = dev->dev_private;
  795. struct drm_display_mode *scan;
  796. int temp_downclock;
  797. temp_downclock = fixed_mode->clock;
  798. list_for_each_entry(scan, &connector->probed_modes, head) {
  799. /*
  800. * If one mode has the same resolution with the fixed_panel
  801. * mode while they have the different refresh rate, it means
  802. * that the reduced downclock is found for the LVDS. In such
  803. * case we can set the different FPx0/1 to dynamically select
  804. * between low and high frequency.
  805. */
  806. if (scan->hdisplay == fixed_mode->hdisplay &&
  807. scan->hsync_start == fixed_mode->hsync_start &&
  808. scan->hsync_end == fixed_mode->hsync_end &&
  809. scan->htotal == fixed_mode->htotal &&
  810. scan->vdisplay == fixed_mode->vdisplay &&
  811. scan->vsync_start == fixed_mode->vsync_start &&
  812. scan->vsync_end == fixed_mode->vsync_end &&
  813. scan->vtotal == fixed_mode->vtotal) {
  814. if (scan->clock < temp_downclock) {
  815. /*
  816. * The downclock is already found. But we
  817. * expect to find the lower downclock.
  818. */
  819. temp_downclock = scan->clock;
  820. }
  821. }
  822. }
  823. if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {
  824. /* We found the downclock for LVDS. */
  825. dev_priv->lvds_downclock_avail = 1;
  826. dev_priv->lvds_downclock = temp_downclock;
  827. DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
  828. "Normal clock %dKhz, downclock %dKhz\n",
  829. fixed_mode->clock, temp_downclock);
  830. }
  831. }
  832. /*
  833. * Enumerate the child dev array parsed from VBT to check whether
  834. * the LVDS is present.
  835. * If it is present, return 1.
  836. * If it is not present, return false.
  837. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  838. */
  839. static bool lvds_is_present_in_vbt(struct drm_device *dev,
  840. u8 *i2c_pin)
  841. {
  842. struct drm_i915_private *dev_priv = dev->dev_private;
  843. int i;
  844. if (!dev_priv->child_dev_num)
  845. return true;
  846. for (i = 0; i < dev_priv->child_dev_num; i++) {
  847. struct child_device_config *child = dev_priv->child_dev + i;
  848. /* If the device type is not LFP, continue.
  849. * We have to check both the new identifiers as well as the
  850. * old for compatibility with some BIOSes.
  851. */
  852. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  853. child->device_type != DEVICE_TYPE_LFP)
  854. continue;
  855. if (intel_gmbus_is_port_valid(child->i2c_pin))
  856. *i2c_pin = child->i2c_pin;
  857. /* However, we cannot trust the BIOS writers to populate
  858. * the VBT correctly. Since LVDS requires additional
  859. * information from AIM blocks, a non-zero addin offset is
  860. * a good indicator that the LVDS is actually present.
  861. */
  862. if (child->addin_offset)
  863. return true;
  864. /* But even then some BIOS writers perform some black magic
  865. * and instantiate the device without reference to any
  866. * additional data. Trust that if the VBT was written into
  867. * the OpRegion then they have validated the LVDS's existence.
  868. */
  869. if (dev_priv->opregion.vbt)
  870. return true;
  871. }
  872. return false;
  873. }
  874. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  875. {
  876. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  877. return 1;
  878. }
  879. static const struct dmi_system_id intel_dual_link_lvds[] = {
  880. {
  881. .callback = intel_dual_link_lvds_callback,
  882. .ident = "Apple MacBook Pro (Core i5/i7 Series)",
  883. .matches = {
  884. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  885. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  886. },
  887. },
  888. { } /* terminating entry */
  889. };
  890. bool intel_is_dual_link_lvds(struct drm_device *dev)
  891. {
  892. struct intel_encoder *encoder;
  893. struct intel_lvds_encoder *lvds_encoder;
  894. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  895. base.head) {
  896. if (encoder->type == INTEL_OUTPUT_LVDS) {
  897. lvds_encoder = to_lvds_encoder(&encoder->base);
  898. return lvds_encoder->is_dual_link;
  899. }
  900. }
  901. return false;
  902. }
  903. static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
  904. {
  905. struct drm_device *dev = lvds_encoder->base.base.dev;
  906. unsigned int val;
  907. struct drm_i915_private *dev_priv = dev->dev_private;
  908. /* use the module option value if specified */
  909. if (i915_lvds_channel_mode > 0)
  910. return i915_lvds_channel_mode == 2;
  911. if (dmi_check_system(intel_dual_link_lvds))
  912. return true;
  913. /* BIOS should set the proper LVDS register value at boot, but
  914. * in reality, it doesn't set the value when the lid is closed;
  915. * we need to check "the value to be set" in VBT when LVDS
  916. * register is uninitialized.
  917. */
  918. val = I915_READ(lvds_encoder->reg);
  919. if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
  920. val = dev_priv->bios_lvds_val;
  921. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  922. }
  923. static bool intel_lvds_supported(struct drm_device *dev)
  924. {
  925. /* With the introduction of the PCH we gained a dedicated
  926. * LVDS presence pin, use it. */
  927. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  928. return true;
  929. /* Otherwise LVDS was only attached to mobile products,
  930. * except for the inglorious 830gm */
  931. if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
  932. return true;
  933. return false;
  934. }
  935. /**
  936. * intel_lvds_init - setup LVDS connectors on this device
  937. * @dev: drm device
  938. *
  939. * Create the connector, register the LVDS DDC bus, and try to figure out what
  940. * modes we can display on the LVDS panel (if present).
  941. */
  942. bool intel_lvds_init(struct drm_device *dev)
  943. {
  944. struct drm_i915_private *dev_priv = dev->dev_private;
  945. struct intel_lvds_encoder *lvds_encoder;
  946. struct intel_encoder *intel_encoder;
  947. struct intel_lvds_connector *lvds_connector;
  948. struct intel_connector *intel_connector;
  949. struct drm_connector *connector;
  950. struct drm_encoder *encoder;
  951. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  952. struct drm_display_mode *fixed_mode = NULL;
  953. struct edid *edid;
  954. struct drm_crtc *crtc;
  955. u32 lvds;
  956. int pipe;
  957. u8 pin;
  958. if (!intel_lvds_supported(dev))
  959. return false;
  960. /* Skip init on machines we know falsely report LVDS */
  961. if (dmi_check_system(intel_no_lvds))
  962. return false;
  963. pin = GMBUS_PORT_PANEL;
  964. if (!lvds_is_present_in_vbt(dev, &pin)) {
  965. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  966. return false;
  967. }
  968. if (HAS_PCH_SPLIT(dev)) {
  969. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  970. return false;
  971. if (dev_priv->edp.support) {
  972. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  973. return false;
  974. }
  975. }
  976. lvds_encoder = kzalloc(sizeof(struct intel_lvds_encoder), GFP_KERNEL);
  977. if (!lvds_encoder)
  978. return false;
  979. lvds_connector = kzalloc(sizeof(struct intel_lvds_connector), GFP_KERNEL);
  980. if (!lvds_connector) {
  981. kfree(lvds_encoder);
  982. return false;
  983. }
  984. lvds_encoder->attached_connector = lvds_connector;
  985. if (!HAS_PCH_SPLIT(dev)) {
  986. lvds_encoder->pfit_control = I915_READ(PFIT_CONTROL);
  987. }
  988. intel_encoder = &lvds_encoder->base;
  989. encoder = &intel_encoder->base;
  990. intel_connector = &lvds_connector->base;
  991. connector = &intel_connector->base;
  992. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  993. DRM_MODE_CONNECTOR_LVDS);
  994. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  995. DRM_MODE_ENCODER_LVDS);
  996. intel_encoder->enable = intel_enable_lvds;
  997. intel_encoder->pre_enable = intel_pre_enable_lvds;
  998. intel_encoder->pre_pll_enable = intel_pre_pll_enable_lvds;
  999. intel_encoder->compute_config = intel_lvds_compute_config;
  1000. intel_encoder->disable = intel_disable_lvds;
  1001. intel_encoder->get_hw_state = intel_lvds_get_hw_state;
  1002. intel_connector->get_hw_state = intel_connector_get_hw_state;
  1003. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1004. intel_encoder->type = INTEL_OUTPUT_LVDS;
  1005. intel_encoder->cloneable = false;
  1006. if (HAS_PCH_SPLIT(dev))
  1007. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1008. else if (IS_GEN4(dev))
  1009. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  1010. else
  1011. intel_encoder->crtc_mask = (1 << 1);
  1012. drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
  1013. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  1014. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  1015. connector->interlace_allowed = false;
  1016. connector->doublescan_allowed = false;
  1017. if (HAS_PCH_SPLIT(dev)) {
  1018. lvds_encoder->reg = PCH_LVDS;
  1019. } else {
  1020. lvds_encoder->reg = LVDS;
  1021. }
  1022. /* create the scaling mode property */
  1023. drm_mode_create_scaling_mode_property(dev);
  1024. drm_object_attach_property(&connector->base,
  1025. dev->mode_config.scaling_mode_property,
  1026. DRM_MODE_SCALE_ASPECT);
  1027. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  1028. /*
  1029. * LVDS discovery:
  1030. * 1) check for EDID on DDC
  1031. * 2) check for VBT data
  1032. * 3) check to see if LVDS is already on
  1033. * if none of the above, no panel
  1034. * 4) make sure lid is open
  1035. * if closed, act like it's not there for now
  1036. */
  1037. /*
  1038. * Attempt to get the fixed panel mode from DDC. Assume that the
  1039. * preferred mode is the right one.
  1040. */
  1041. edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
  1042. if (edid) {
  1043. if (drm_add_edid_modes(connector, edid)) {
  1044. drm_mode_connector_update_edid_property(connector,
  1045. edid);
  1046. } else {
  1047. kfree(edid);
  1048. edid = ERR_PTR(-EINVAL);
  1049. }
  1050. } else {
  1051. edid = ERR_PTR(-ENOENT);
  1052. }
  1053. lvds_connector->base.edid = edid;
  1054. if (IS_ERR_OR_NULL(edid)) {
  1055. /* Didn't get an EDID, so
  1056. * Set wide sync ranges so we get all modes
  1057. * handed to valid_mode for checking
  1058. */
  1059. connector->display_info.min_vfreq = 0;
  1060. connector->display_info.max_vfreq = 200;
  1061. connector->display_info.min_hfreq = 0;
  1062. connector->display_info.max_hfreq = 200;
  1063. }
  1064. list_for_each_entry(scan, &connector->probed_modes, head) {
  1065. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  1066. DRM_DEBUG_KMS("using preferred mode from EDID: ");
  1067. drm_mode_debug_printmodeline(scan);
  1068. fixed_mode = drm_mode_duplicate(dev, scan);
  1069. if (fixed_mode) {
  1070. intel_find_lvds_downclock(dev, fixed_mode,
  1071. connector);
  1072. goto out;
  1073. }
  1074. }
  1075. }
  1076. /* Failed to get EDID, what about VBT? */
  1077. if (dev_priv->lfp_lvds_vbt_mode) {
  1078. DRM_DEBUG_KMS("using mode from VBT: ");
  1079. drm_mode_debug_printmodeline(dev_priv->lfp_lvds_vbt_mode);
  1080. fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  1081. if (fixed_mode) {
  1082. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1083. goto out;
  1084. }
  1085. }
  1086. /*
  1087. * If we didn't get EDID, try checking if the panel is already turned
  1088. * on. If so, assume that whatever is currently programmed is the
  1089. * correct mode.
  1090. */
  1091. /* Ironlake: FIXME if still fail, not try pipe mode now */
  1092. if (HAS_PCH_SPLIT(dev))
  1093. goto failed;
  1094. lvds = I915_READ(LVDS);
  1095. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  1096. crtc = intel_get_crtc_for_pipe(dev, pipe);
  1097. if (crtc && (lvds & LVDS_PORT_EN)) {
  1098. fixed_mode = intel_crtc_mode_get(dev, crtc);
  1099. if (fixed_mode) {
  1100. DRM_DEBUG_KMS("using current (BIOS) mode: ");
  1101. drm_mode_debug_printmodeline(fixed_mode);
  1102. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1103. goto out;
  1104. }
  1105. }
  1106. /* If we still don't have a mode after all that, give up. */
  1107. if (!fixed_mode)
  1108. goto failed;
  1109. out:
  1110. lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
  1111. DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
  1112. lvds_encoder->is_dual_link ? "dual" : "single");
  1113. /*
  1114. * Unlock registers and just
  1115. * leave them unlocked
  1116. */
  1117. if (HAS_PCH_SPLIT(dev)) {
  1118. I915_WRITE(PCH_PP_CONTROL,
  1119. I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
  1120. } else {
  1121. I915_WRITE(PP_CONTROL,
  1122. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  1123. }
  1124. lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
  1125. if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
  1126. DRM_DEBUG_KMS("lid notifier registration failed\n");
  1127. lvds_connector->lid_notifier.notifier_call = NULL;
  1128. }
  1129. drm_sysfs_connector_add(connector);
  1130. intel_panel_init(&intel_connector->panel, fixed_mode);
  1131. intel_panel_setup_backlight(connector);
  1132. return true;
  1133. failed:
  1134. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  1135. drm_connector_cleanup(connector);
  1136. drm_encoder_cleanup(encoder);
  1137. if (fixed_mode)
  1138. drm_mode_destroy(dev, fixed_mode);
  1139. kfree(lvds_encoder);
  1140. kfree(lvds_connector);
  1141. return false;
  1142. }