intel_lvds.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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 <linux/vga_switcheroo.h>
  34. #include <drm/drmP.h>
  35. #include <drm/drm_atomic_helper.h>
  36. #include <drm/drm_crtc.h>
  37. #include <drm/drm_edid.h>
  38. #include "intel_drv.h"
  39. #include <drm/i915_drm.h>
  40. #include "i915_drv.h"
  41. #include <linux/acpi.h>
  42. /* Private structure for the integrated LVDS support */
  43. struct intel_lvds_connector {
  44. struct intel_connector base;
  45. struct notifier_block lid_notifier;
  46. };
  47. struct intel_lvds_pps {
  48. /* 100us units */
  49. int t1_t2;
  50. int t3;
  51. int t4;
  52. int t5;
  53. int tx;
  54. int divider;
  55. int port;
  56. bool powerdown_on_reset;
  57. };
  58. struct intel_lvds_encoder {
  59. struct intel_encoder base;
  60. bool is_dual_link;
  61. i915_reg_t reg;
  62. u32 a3_power;
  63. struct intel_lvds_pps init_pps;
  64. u32 init_lvds_val;
  65. struct intel_lvds_connector *attached_connector;
  66. };
  67. static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
  68. {
  69. return container_of(encoder, struct intel_lvds_encoder, base.base);
  70. }
  71. static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
  72. {
  73. return container_of(connector, struct intel_lvds_connector, base.base);
  74. }
  75. static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
  76. enum pipe *pipe)
  77. {
  78. struct drm_device *dev = encoder->base.dev;
  79. struct drm_i915_private *dev_priv = to_i915(dev);
  80. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  81. enum intel_display_power_domain power_domain;
  82. u32 tmp;
  83. bool ret;
  84. power_domain = intel_display_port_power_domain(encoder);
  85. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  86. return false;
  87. ret = false;
  88. tmp = I915_READ(lvds_encoder->reg);
  89. if (!(tmp & LVDS_PORT_EN))
  90. goto out;
  91. if (HAS_PCH_CPT(dev))
  92. *pipe = PORT_TO_PIPE_CPT(tmp);
  93. else
  94. *pipe = PORT_TO_PIPE(tmp);
  95. ret = true;
  96. out:
  97. intel_display_power_put(dev_priv, power_domain);
  98. return ret;
  99. }
  100. static void intel_lvds_get_config(struct intel_encoder *encoder,
  101. struct intel_crtc_state *pipe_config)
  102. {
  103. struct drm_device *dev = encoder->base.dev;
  104. struct drm_i915_private *dev_priv = to_i915(dev);
  105. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  106. u32 tmp, flags = 0;
  107. tmp = I915_READ(lvds_encoder->reg);
  108. if (tmp & LVDS_HSYNC_POLARITY)
  109. flags |= DRM_MODE_FLAG_NHSYNC;
  110. else
  111. flags |= DRM_MODE_FLAG_PHSYNC;
  112. if (tmp & LVDS_VSYNC_POLARITY)
  113. flags |= DRM_MODE_FLAG_NVSYNC;
  114. else
  115. flags |= DRM_MODE_FLAG_PVSYNC;
  116. pipe_config->base.adjusted_mode.flags |= flags;
  117. if (INTEL_INFO(dev)->gen < 5)
  118. pipe_config->gmch_pfit.lvds_border_bits =
  119. tmp & LVDS_BORDER_ENABLE;
  120. /* gen2/3 store dither state in pfit control, needs to match */
  121. if (INTEL_INFO(dev)->gen < 4) {
  122. tmp = I915_READ(PFIT_CONTROL);
  123. pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
  124. }
  125. pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
  126. }
  127. static void intel_lvds_pps_get_hw_state(struct drm_i915_private *dev_priv,
  128. struct intel_lvds_pps *pps)
  129. {
  130. u32 val;
  131. pps->powerdown_on_reset = I915_READ(PP_CONTROL(0)) & PANEL_POWER_RESET;
  132. val = I915_READ(PP_ON_DELAYS(0));
  133. pps->port = (val & PANEL_PORT_SELECT_MASK) >>
  134. PANEL_PORT_SELECT_SHIFT;
  135. pps->t1_t2 = (val & PANEL_POWER_UP_DELAY_MASK) >>
  136. PANEL_POWER_UP_DELAY_SHIFT;
  137. pps->t5 = (val & PANEL_LIGHT_ON_DELAY_MASK) >>
  138. PANEL_LIGHT_ON_DELAY_SHIFT;
  139. val = I915_READ(PP_OFF_DELAYS(0));
  140. pps->t3 = (val & PANEL_POWER_DOWN_DELAY_MASK) >>
  141. PANEL_POWER_DOWN_DELAY_SHIFT;
  142. pps->tx = (val & PANEL_LIGHT_OFF_DELAY_MASK) >>
  143. PANEL_LIGHT_OFF_DELAY_SHIFT;
  144. val = I915_READ(PP_DIVISOR(0));
  145. pps->divider = (val & PP_REFERENCE_DIVIDER_MASK) >>
  146. PP_REFERENCE_DIVIDER_SHIFT;
  147. val = (val & PANEL_POWER_CYCLE_DELAY_MASK) >>
  148. PANEL_POWER_CYCLE_DELAY_SHIFT;
  149. /*
  150. * Remove the BSpec specified +1 (100ms) offset that accounts for a
  151. * too short power-cycle delay due to the asynchronous programming of
  152. * the register.
  153. */
  154. if (val)
  155. val--;
  156. /* Convert from 100ms to 100us units */
  157. pps->t4 = val * 1000;
  158. if (INTEL_INFO(dev_priv)->gen <= 4 &&
  159. pps->t1_t2 == 0 && pps->t5 == 0 && pps->t3 == 0 && pps->tx == 0) {
  160. DRM_DEBUG_KMS("Panel power timings uninitialized, "
  161. "setting defaults\n");
  162. /* Set T2 to 40ms and T5 to 200ms in 100 usec units */
  163. pps->t1_t2 = 40 * 10;
  164. pps->t5 = 200 * 10;
  165. /* Set T3 to 35ms and Tx to 200ms in 100 usec units */
  166. pps->t3 = 35 * 10;
  167. pps->tx = 200 * 10;
  168. }
  169. DRM_DEBUG_DRIVER("LVDS PPS:t1+t2 %d t3 %d t4 %d t5 %d tx %d "
  170. "divider %d port %d powerdown_on_reset %d\n",
  171. pps->t1_t2, pps->t3, pps->t4, pps->t5, pps->tx,
  172. pps->divider, pps->port, pps->powerdown_on_reset);
  173. }
  174. static void intel_lvds_pps_init_hw(struct drm_i915_private *dev_priv,
  175. struct intel_lvds_pps *pps)
  176. {
  177. u32 val;
  178. val = I915_READ(PP_CONTROL(0));
  179. WARN_ON((val & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS);
  180. if (pps->powerdown_on_reset)
  181. val |= PANEL_POWER_RESET;
  182. I915_WRITE(PP_CONTROL(0), val);
  183. I915_WRITE(PP_ON_DELAYS(0), (pps->port << PANEL_PORT_SELECT_SHIFT) |
  184. (pps->t1_t2 << PANEL_POWER_UP_DELAY_SHIFT) |
  185. (pps->t5 << PANEL_LIGHT_ON_DELAY_SHIFT));
  186. I915_WRITE(PP_OFF_DELAYS(0), (pps->t3 << PANEL_POWER_DOWN_DELAY_SHIFT) |
  187. (pps->tx << PANEL_LIGHT_OFF_DELAY_SHIFT));
  188. val = pps->divider << PP_REFERENCE_DIVIDER_SHIFT;
  189. val |= (DIV_ROUND_UP(pps->t4, 1000) + 1) <<
  190. PANEL_POWER_CYCLE_DELAY_SHIFT;
  191. I915_WRITE(PP_DIVISOR(0), val);
  192. }
  193. static void intel_pre_enable_lvds(struct intel_encoder *encoder,
  194. struct intel_crtc_state *pipe_config,
  195. struct drm_connector_state *conn_state)
  196. {
  197. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  198. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  199. struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  200. const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  201. int pipe = crtc->pipe;
  202. u32 temp;
  203. if (HAS_PCH_SPLIT(dev_priv)) {
  204. assert_fdi_rx_pll_disabled(dev_priv, pipe);
  205. assert_shared_dpll_disabled(dev_priv,
  206. pipe_config->shared_dpll);
  207. } else {
  208. assert_pll_disabled(dev_priv, pipe);
  209. }
  210. intel_lvds_pps_init_hw(dev_priv, &lvds_encoder->init_pps);
  211. temp = lvds_encoder->init_lvds_val;
  212. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  213. if (HAS_PCH_CPT(dev_priv)) {
  214. temp &= ~PORT_TRANS_SEL_MASK;
  215. temp |= PORT_TRANS_SEL_CPT(pipe);
  216. } else {
  217. if (pipe == 1) {
  218. temp |= LVDS_PIPEB_SELECT;
  219. } else {
  220. temp &= ~LVDS_PIPEB_SELECT;
  221. }
  222. }
  223. /* set the corresponsding LVDS_BORDER bit */
  224. temp &= ~LVDS_BORDER_ENABLE;
  225. temp |= pipe_config->gmch_pfit.lvds_border_bits;
  226. /* Set the B0-B3 data pairs corresponding to whether we're going to
  227. * set the DPLLs for dual-channel mode or not.
  228. */
  229. if (lvds_encoder->is_dual_link)
  230. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  231. else
  232. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  233. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  234. * appropriately here, but we need to look more thoroughly into how
  235. * panels behave in the two modes. For now, let's just maintain the
  236. * value we got from the BIOS.
  237. */
  238. temp &= ~LVDS_A3_POWER_MASK;
  239. temp |= lvds_encoder->a3_power;
  240. /* Set the dithering flag on LVDS as needed, note that there is no
  241. * special lvds dither control bit on pch-split platforms, dithering is
  242. * only controlled through the PIPECONF reg. */
  243. if (IS_GEN4(dev_priv)) {
  244. /* Bspec wording suggests that LVDS port dithering only exists
  245. * for 18bpp panels. */
  246. if (pipe_config->dither && pipe_config->pipe_bpp == 18)
  247. temp |= LVDS_ENABLE_DITHER;
  248. else
  249. temp &= ~LVDS_ENABLE_DITHER;
  250. }
  251. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  252. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  253. temp |= LVDS_HSYNC_POLARITY;
  254. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  255. temp |= LVDS_VSYNC_POLARITY;
  256. I915_WRITE(lvds_encoder->reg, temp);
  257. }
  258. /**
  259. * Sets the power state for the panel.
  260. */
  261. static void intel_enable_lvds(struct intel_encoder *encoder,
  262. struct intel_crtc_state *pipe_config,
  263. struct drm_connector_state *conn_state)
  264. {
  265. struct drm_device *dev = encoder->base.dev;
  266. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  267. struct intel_connector *intel_connector =
  268. &lvds_encoder->attached_connector->base;
  269. struct drm_i915_private *dev_priv = to_i915(dev);
  270. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
  271. I915_WRITE(PP_CONTROL(0), I915_READ(PP_CONTROL(0)) | PANEL_POWER_ON);
  272. POSTING_READ(lvds_encoder->reg);
  273. if (intel_wait_for_register(dev_priv, PP_STATUS(0), PP_ON, PP_ON, 1000))
  274. DRM_ERROR("timed out waiting for panel to power on\n");
  275. intel_panel_enable_backlight(intel_connector);
  276. }
  277. static void intel_disable_lvds(struct intel_encoder *encoder,
  278. struct intel_crtc_state *old_crtc_state,
  279. struct drm_connector_state *old_conn_state)
  280. {
  281. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  282. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  283. I915_WRITE(PP_CONTROL(0), I915_READ(PP_CONTROL(0)) & ~PANEL_POWER_ON);
  284. if (intel_wait_for_register(dev_priv, PP_STATUS(0), PP_ON, 0, 1000))
  285. DRM_ERROR("timed out waiting for panel to power off\n");
  286. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
  287. POSTING_READ(lvds_encoder->reg);
  288. }
  289. static void gmch_disable_lvds(struct intel_encoder *encoder,
  290. struct intel_crtc_state *old_crtc_state,
  291. struct drm_connector_state *old_conn_state)
  292. {
  293. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  294. struct intel_connector *intel_connector =
  295. &lvds_encoder->attached_connector->base;
  296. intel_panel_disable_backlight(intel_connector);
  297. intel_disable_lvds(encoder, old_crtc_state, old_conn_state);
  298. }
  299. static void pch_disable_lvds(struct intel_encoder *encoder,
  300. struct intel_crtc_state *old_crtc_state,
  301. struct drm_connector_state *old_conn_state)
  302. {
  303. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  304. struct intel_connector *intel_connector =
  305. &lvds_encoder->attached_connector->base;
  306. intel_panel_disable_backlight(intel_connector);
  307. }
  308. static void pch_post_disable_lvds(struct intel_encoder *encoder,
  309. struct intel_crtc_state *old_crtc_state,
  310. struct drm_connector_state *old_conn_state)
  311. {
  312. intel_disable_lvds(encoder, old_crtc_state, old_conn_state);
  313. }
  314. static enum drm_mode_status
  315. intel_lvds_mode_valid(struct drm_connector *connector,
  316. struct drm_display_mode *mode)
  317. {
  318. struct intel_connector *intel_connector = to_intel_connector(connector);
  319. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  320. int max_pixclk = to_i915(connector->dev)->max_dotclk_freq;
  321. if (mode->hdisplay > fixed_mode->hdisplay)
  322. return MODE_PANEL;
  323. if (mode->vdisplay > fixed_mode->vdisplay)
  324. return MODE_PANEL;
  325. if (fixed_mode->clock > max_pixclk)
  326. return MODE_CLOCK_HIGH;
  327. return MODE_OK;
  328. }
  329. static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
  330. struct intel_crtc_state *pipe_config,
  331. struct drm_connector_state *conn_state)
  332. {
  333. struct drm_device *dev = intel_encoder->base.dev;
  334. struct intel_lvds_encoder *lvds_encoder =
  335. to_lvds_encoder(&intel_encoder->base);
  336. struct intel_connector *intel_connector =
  337. &lvds_encoder->attached_connector->base;
  338. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  339. struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
  340. unsigned int lvds_bpp;
  341. /* Should never happen!! */
  342. if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
  343. DRM_ERROR("Can't support LVDS on pipe A\n");
  344. return false;
  345. }
  346. if (lvds_encoder->a3_power == LVDS_A3_POWER_UP)
  347. lvds_bpp = 8*3;
  348. else
  349. lvds_bpp = 6*3;
  350. if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
  351. DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
  352. pipe_config->pipe_bpp, lvds_bpp);
  353. pipe_config->pipe_bpp = lvds_bpp;
  354. }
  355. /*
  356. * We have timings from the BIOS for the panel, put them in
  357. * to the adjusted mode. The CRTC will be set up for this mode,
  358. * with the panel scaling set up to source from the H/VDisplay
  359. * of the original mode.
  360. */
  361. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  362. adjusted_mode);
  363. if (HAS_PCH_SPLIT(dev)) {
  364. pipe_config->has_pch_encoder = true;
  365. intel_pch_panel_fitting(intel_crtc, pipe_config,
  366. intel_connector->panel.fitting_mode);
  367. } else {
  368. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  369. intel_connector->panel.fitting_mode);
  370. }
  371. /*
  372. * XXX: It would be nice to support lower refresh rates on the
  373. * panels to reduce power consumption, and perhaps match the
  374. * user's requested refresh rate.
  375. */
  376. return true;
  377. }
  378. /**
  379. * Detect the LVDS connection.
  380. *
  381. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  382. * connected and closed means disconnected. We also send hotplug events as
  383. * needed, using lid status notification from the input layer.
  384. */
  385. static enum drm_connector_status
  386. intel_lvds_detect(struct drm_connector *connector, bool force)
  387. {
  388. struct drm_device *dev = connector->dev;
  389. enum drm_connector_status status;
  390. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  391. connector->base.id, connector->name);
  392. status = intel_panel_detect(dev);
  393. if (status != connector_status_unknown)
  394. return status;
  395. return connector_status_connected;
  396. }
  397. /**
  398. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  399. */
  400. static int intel_lvds_get_modes(struct drm_connector *connector)
  401. {
  402. struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
  403. struct drm_device *dev = connector->dev;
  404. struct drm_display_mode *mode;
  405. /* use cached edid if we have one */
  406. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  407. return drm_add_edid_modes(connector, lvds_connector->base.edid);
  408. mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
  409. if (mode == NULL)
  410. return 0;
  411. drm_mode_probed_add(connector, mode);
  412. return 1;
  413. }
  414. static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
  415. {
  416. DRM_INFO("Skipping forced modeset for %s\n", id->ident);
  417. return 1;
  418. }
  419. /* The GPU hangs up on these systems if modeset is performed on LID open */
  420. static const struct dmi_system_id intel_no_modeset_on_lid[] = {
  421. {
  422. .callback = intel_no_modeset_on_lid_dmi_callback,
  423. .ident = "Toshiba Tecra A11",
  424. .matches = {
  425. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  426. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
  427. },
  428. },
  429. { } /* terminating entry */
  430. };
  431. /*
  432. * Lid events. Note the use of 'modeset':
  433. * - we set it to MODESET_ON_LID_OPEN on lid close,
  434. * and set it to MODESET_DONE on open
  435. * - we use it as a "only once" bit (ie we ignore
  436. * duplicate events where it was already properly set)
  437. * - the suspend/resume paths will set it to
  438. * MODESET_SUSPENDED and ignore the lid open event,
  439. * because they restore the mode ("lid open").
  440. */
  441. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  442. void *unused)
  443. {
  444. struct intel_lvds_connector *lvds_connector =
  445. container_of(nb, struct intel_lvds_connector, lid_notifier);
  446. struct drm_connector *connector = &lvds_connector->base.base;
  447. struct drm_device *dev = connector->dev;
  448. struct drm_i915_private *dev_priv = to_i915(dev);
  449. if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
  450. return NOTIFY_OK;
  451. mutex_lock(&dev_priv->modeset_restore_lock);
  452. if (dev_priv->modeset_restore == MODESET_SUSPENDED)
  453. goto exit;
  454. /*
  455. * check and update the status of LVDS connector after receiving
  456. * the LID nofication event.
  457. */
  458. connector->status = connector->funcs->detect(connector, false);
  459. /* Don't force modeset on machines where it causes a GPU lockup */
  460. if (dmi_check_system(intel_no_modeset_on_lid))
  461. goto exit;
  462. if (!acpi_lid_open()) {
  463. /* do modeset on next lid open event */
  464. dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
  465. goto exit;
  466. }
  467. if (dev_priv->modeset_restore == MODESET_DONE)
  468. goto exit;
  469. /*
  470. * Some old platform's BIOS love to wreak havoc while the lid is closed.
  471. * We try to detect this here and undo any damage. The split for PCH
  472. * platforms is rather conservative and a bit arbitrary expect that on
  473. * those platforms VGA disabling requires actual legacy VGA I/O access,
  474. * and as part of the cleanup in the hw state restore we also redisable
  475. * the vga plane.
  476. */
  477. if (!HAS_PCH_SPLIT(dev))
  478. intel_display_resume(dev);
  479. dev_priv->modeset_restore = MODESET_DONE;
  480. exit:
  481. mutex_unlock(&dev_priv->modeset_restore_lock);
  482. return NOTIFY_OK;
  483. }
  484. /**
  485. * intel_lvds_destroy - unregister and free LVDS structures
  486. * @connector: connector to free
  487. *
  488. * Unregister the DDC bus for this connector then free the driver private
  489. * structure.
  490. */
  491. static void intel_lvds_destroy(struct drm_connector *connector)
  492. {
  493. struct intel_lvds_connector *lvds_connector =
  494. to_lvds_connector(connector);
  495. if (lvds_connector->lid_notifier.notifier_call)
  496. acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
  497. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  498. kfree(lvds_connector->base.edid);
  499. intel_panel_fini(&lvds_connector->base.panel);
  500. drm_connector_cleanup(connector);
  501. kfree(connector);
  502. }
  503. static int intel_lvds_set_property(struct drm_connector *connector,
  504. struct drm_property *property,
  505. uint64_t value)
  506. {
  507. struct intel_connector *intel_connector = to_intel_connector(connector);
  508. struct drm_device *dev = connector->dev;
  509. if (property == dev->mode_config.scaling_mode_property) {
  510. struct drm_crtc *crtc;
  511. if (value == DRM_MODE_SCALE_NONE) {
  512. DRM_DEBUG_KMS("no scaling not supported\n");
  513. return -EINVAL;
  514. }
  515. if (intel_connector->panel.fitting_mode == value) {
  516. /* the LVDS scaling property is not changed */
  517. return 0;
  518. }
  519. intel_connector->panel.fitting_mode = value;
  520. crtc = intel_attached_encoder(connector)->base.crtc;
  521. if (crtc && crtc->state->enable) {
  522. /*
  523. * If the CRTC is enabled, the display will be changed
  524. * according to the new panel fitting mode.
  525. */
  526. intel_crtc_restore_mode(crtc);
  527. }
  528. }
  529. return 0;
  530. }
  531. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  532. .get_modes = intel_lvds_get_modes,
  533. .mode_valid = intel_lvds_mode_valid,
  534. };
  535. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  536. .dpms = drm_atomic_helper_connector_dpms,
  537. .detect = intel_lvds_detect,
  538. .fill_modes = drm_helper_probe_single_connector_modes,
  539. .set_property = intel_lvds_set_property,
  540. .atomic_get_property = intel_connector_atomic_get_property,
  541. .late_register = intel_connector_register,
  542. .early_unregister = intel_connector_unregister,
  543. .destroy = intel_lvds_destroy,
  544. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  545. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  546. };
  547. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  548. .destroy = intel_encoder_destroy,
  549. };
  550. static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  551. {
  552. DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
  553. return 1;
  554. }
  555. /* These systems claim to have LVDS, but really don't */
  556. static const struct dmi_system_id intel_no_lvds[] = {
  557. {
  558. .callback = intel_no_lvds_dmi_callback,
  559. .ident = "Apple Mac Mini (Core series)",
  560. .matches = {
  561. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  562. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  563. },
  564. },
  565. {
  566. .callback = intel_no_lvds_dmi_callback,
  567. .ident = "Apple Mac Mini (Core 2 series)",
  568. .matches = {
  569. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  570. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  571. },
  572. },
  573. {
  574. .callback = intel_no_lvds_dmi_callback,
  575. .ident = "MSI IM-945GSE-A",
  576. .matches = {
  577. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  578. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  579. },
  580. },
  581. {
  582. .callback = intel_no_lvds_dmi_callback,
  583. .ident = "Dell Studio Hybrid",
  584. .matches = {
  585. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  586. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  587. },
  588. },
  589. {
  590. .callback = intel_no_lvds_dmi_callback,
  591. .ident = "Dell OptiPlex FX170",
  592. .matches = {
  593. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  594. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
  595. },
  596. },
  597. {
  598. .callback = intel_no_lvds_dmi_callback,
  599. .ident = "AOpen Mini PC",
  600. .matches = {
  601. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  602. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  603. },
  604. },
  605. {
  606. .callback = intel_no_lvds_dmi_callback,
  607. .ident = "AOpen Mini PC MP915",
  608. .matches = {
  609. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  610. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  611. },
  612. },
  613. {
  614. .callback = intel_no_lvds_dmi_callback,
  615. .ident = "AOpen i915GMm-HFS",
  616. .matches = {
  617. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  618. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  619. },
  620. },
  621. {
  622. .callback = intel_no_lvds_dmi_callback,
  623. .ident = "AOpen i45GMx-I",
  624. .matches = {
  625. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  626. DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
  627. },
  628. },
  629. {
  630. .callback = intel_no_lvds_dmi_callback,
  631. .ident = "Aopen i945GTt-VFA",
  632. .matches = {
  633. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  634. },
  635. },
  636. {
  637. .callback = intel_no_lvds_dmi_callback,
  638. .ident = "Clientron U800",
  639. .matches = {
  640. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  641. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  642. },
  643. },
  644. {
  645. .callback = intel_no_lvds_dmi_callback,
  646. .ident = "Clientron E830",
  647. .matches = {
  648. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  649. DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
  650. },
  651. },
  652. {
  653. .callback = intel_no_lvds_dmi_callback,
  654. .ident = "Asus EeeBox PC EB1007",
  655. .matches = {
  656. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  657. DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
  658. },
  659. },
  660. {
  661. .callback = intel_no_lvds_dmi_callback,
  662. .ident = "Asus AT5NM10T-I",
  663. .matches = {
  664. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  665. DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
  666. },
  667. },
  668. {
  669. .callback = intel_no_lvds_dmi_callback,
  670. .ident = "Hewlett-Packard HP t5740",
  671. .matches = {
  672. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  673. DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
  674. },
  675. },
  676. {
  677. .callback = intel_no_lvds_dmi_callback,
  678. .ident = "Hewlett-Packard t5745",
  679. .matches = {
  680. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  681. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
  682. },
  683. },
  684. {
  685. .callback = intel_no_lvds_dmi_callback,
  686. .ident = "Hewlett-Packard st5747",
  687. .matches = {
  688. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  689. DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
  690. },
  691. },
  692. {
  693. .callback = intel_no_lvds_dmi_callback,
  694. .ident = "MSI Wind Box DC500",
  695. .matches = {
  696. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  697. DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
  698. },
  699. },
  700. {
  701. .callback = intel_no_lvds_dmi_callback,
  702. .ident = "Gigabyte GA-D525TUD",
  703. .matches = {
  704. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  705. DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
  706. },
  707. },
  708. {
  709. .callback = intel_no_lvds_dmi_callback,
  710. .ident = "Supermicro X7SPA-H",
  711. .matches = {
  712. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  713. DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
  714. },
  715. },
  716. {
  717. .callback = intel_no_lvds_dmi_callback,
  718. .ident = "Fujitsu Esprimo Q900",
  719. .matches = {
  720. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  721. DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
  722. },
  723. },
  724. {
  725. .callback = intel_no_lvds_dmi_callback,
  726. .ident = "Intel D410PT",
  727. .matches = {
  728. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  729. DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
  730. },
  731. },
  732. {
  733. .callback = intel_no_lvds_dmi_callback,
  734. .ident = "Intel D425KT",
  735. .matches = {
  736. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  737. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
  738. },
  739. },
  740. {
  741. .callback = intel_no_lvds_dmi_callback,
  742. .ident = "Intel D510MO",
  743. .matches = {
  744. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  745. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
  746. },
  747. },
  748. {
  749. .callback = intel_no_lvds_dmi_callback,
  750. .ident = "Intel D525MW",
  751. .matches = {
  752. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  753. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
  754. },
  755. },
  756. { } /* terminating entry */
  757. };
  758. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  759. {
  760. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  761. return 1;
  762. }
  763. static const struct dmi_system_id intel_dual_link_lvds[] = {
  764. {
  765. .callback = intel_dual_link_lvds_callback,
  766. .ident = "Apple MacBook Pro 15\" (2010)",
  767. .matches = {
  768. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  769. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
  770. },
  771. },
  772. {
  773. .callback = intel_dual_link_lvds_callback,
  774. .ident = "Apple MacBook Pro 15\" (2011)",
  775. .matches = {
  776. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  777. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  778. },
  779. },
  780. {
  781. .callback = intel_dual_link_lvds_callback,
  782. .ident = "Apple MacBook Pro 15\" (2012)",
  783. .matches = {
  784. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  785. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
  786. },
  787. },
  788. { } /* terminating entry */
  789. };
  790. struct intel_encoder *intel_get_lvds_encoder(struct drm_device *dev)
  791. {
  792. struct intel_encoder *intel_encoder;
  793. for_each_intel_encoder(dev, intel_encoder)
  794. if (intel_encoder->type == INTEL_OUTPUT_LVDS)
  795. return intel_encoder;
  796. return NULL;
  797. }
  798. bool intel_is_dual_link_lvds(struct drm_device *dev)
  799. {
  800. struct intel_encoder *encoder = intel_get_lvds_encoder(dev);
  801. return encoder && to_lvds_encoder(&encoder->base)->is_dual_link;
  802. }
  803. static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
  804. {
  805. struct drm_device *dev = lvds_encoder->base.base.dev;
  806. unsigned int val;
  807. struct drm_i915_private *dev_priv = to_i915(dev);
  808. /* use the module option value if specified */
  809. if (i915.lvds_channel_mode > 0)
  810. return i915.lvds_channel_mode == 2;
  811. /* single channel LVDS is limited to 112 MHz */
  812. if (lvds_encoder->attached_connector->base.panel.fixed_mode->clock
  813. > 112999)
  814. return true;
  815. if (dmi_check_system(intel_dual_link_lvds))
  816. return true;
  817. /* BIOS should set the proper LVDS register value at boot, but
  818. * in reality, it doesn't set the value when the lid is closed;
  819. * we need to check "the value to be set" in VBT when LVDS
  820. * register is uninitialized.
  821. */
  822. val = I915_READ(lvds_encoder->reg);
  823. if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
  824. val = dev_priv->vbt.bios_lvds_val;
  825. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  826. }
  827. static bool intel_lvds_supported(struct drm_device *dev)
  828. {
  829. /* With the introduction of the PCH we gained a dedicated
  830. * LVDS presence pin, use it. */
  831. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  832. return true;
  833. /* Otherwise LVDS was only attached to mobile products,
  834. * except for the inglorious 830gm */
  835. if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
  836. return true;
  837. return false;
  838. }
  839. /**
  840. * intel_lvds_init - setup LVDS connectors on this device
  841. * @dev: drm device
  842. *
  843. * Create the connector, register the LVDS DDC bus, and try to figure out what
  844. * modes we can display on the LVDS panel (if present).
  845. */
  846. void intel_lvds_init(struct drm_device *dev)
  847. {
  848. struct drm_i915_private *dev_priv = to_i915(dev);
  849. struct intel_lvds_encoder *lvds_encoder;
  850. struct intel_encoder *intel_encoder;
  851. struct intel_lvds_connector *lvds_connector;
  852. struct intel_connector *intel_connector;
  853. struct drm_connector *connector;
  854. struct drm_encoder *encoder;
  855. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  856. struct drm_display_mode *fixed_mode = NULL;
  857. struct drm_display_mode *downclock_mode = NULL;
  858. struct edid *edid;
  859. struct drm_crtc *crtc;
  860. i915_reg_t lvds_reg;
  861. u32 lvds;
  862. int pipe;
  863. u8 pin;
  864. if (!intel_lvds_supported(dev))
  865. return;
  866. /* Skip init on machines we know falsely report LVDS */
  867. if (dmi_check_system(intel_no_lvds))
  868. return;
  869. if (HAS_PCH_SPLIT(dev))
  870. lvds_reg = PCH_LVDS;
  871. else
  872. lvds_reg = LVDS;
  873. lvds = I915_READ(lvds_reg);
  874. if (HAS_PCH_SPLIT(dev)) {
  875. if ((lvds & LVDS_DETECTED) == 0)
  876. return;
  877. if (dev_priv->vbt.edp.support) {
  878. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  879. return;
  880. }
  881. }
  882. pin = GMBUS_PIN_PANEL;
  883. if (!intel_bios_is_lvds_present(dev_priv, &pin)) {
  884. if ((lvds & LVDS_PORT_EN) == 0) {
  885. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  886. return;
  887. }
  888. DRM_DEBUG_KMS("LVDS is not present in VBT, but enabled anyway\n");
  889. }
  890. lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
  891. if (!lvds_encoder)
  892. return;
  893. lvds_connector = kzalloc(sizeof(*lvds_connector), GFP_KERNEL);
  894. if (!lvds_connector) {
  895. kfree(lvds_encoder);
  896. return;
  897. }
  898. if (intel_connector_init(&lvds_connector->base) < 0) {
  899. kfree(lvds_connector);
  900. kfree(lvds_encoder);
  901. return;
  902. }
  903. lvds_encoder->attached_connector = lvds_connector;
  904. intel_encoder = &lvds_encoder->base;
  905. encoder = &intel_encoder->base;
  906. intel_connector = &lvds_connector->base;
  907. connector = &intel_connector->base;
  908. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  909. DRM_MODE_CONNECTOR_LVDS);
  910. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  911. DRM_MODE_ENCODER_LVDS, "LVDS");
  912. intel_encoder->enable = intel_enable_lvds;
  913. intel_encoder->pre_enable = intel_pre_enable_lvds;
  914. intel_encoder->compute_config = intel_lvds_compute_config;
  915. if (HAS_PCH_SPLIT(dev_priv)) {
  916. intel_encoder->disable = pch_disable_lvds;
  917. intel_encoder->post_disable = pch_post_disable_lvds;
  918. } else {
  919. intel_encoder->disable = gmch_disable_lvds;
  920. }
  921. intel_encoder->get_hw_state = intel_lvds_get_hw_state;
  922. intel_encoder->get_config = intel_lvds_get_config;
  923. intel_connector->get_hw_state = intel_connector_get_hw_state;
  924. intel_connector_attach_encoder(intel_connector, intel_encoder);
  925. intel_encoder->type = INTEL_OUTPUT_LVDS;
  926. intel_encoder->cloneable = 0;
  927. if (HAS_PCH_SPLIT(dev))
  928. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  929. else if (IS_GEN4(dev))
  930. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  931. else
  932. intel_encoder->crtc_mask = (1 << 1);
  933. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  934. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  935. connector->interlace_allowed = false;
  936. connector->doublescan_allowed = false;
  937. lvds_encoder->reg = lvds_reg;
  938. /* create the scaling mode property */
  939. drm_mode_create_scaling_mode_property(dev);
  940. drm_object_attach_property(&connector->base,
  941. dev->mode_config.scaling_mode_property,
  942. DRM_MODE_SCALE_ASPECT);
  943. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  944. intel_lvds_pps_get_hw_state(dev_priv, &lvds_encoder->init_pps);
  945. lvds_encoder->init_lvds_val = lvds;
  946. /*
  947. * LVDS discovery:
  948. * 1) check for EDID on DDC
  949. * 2) check for VBT data
  950. * 3) check to see if LVDS is already on
  951. * if none of the above, no panel
  952. * 4) make sure lid is open
  953. * if closed, act like it's not there for now
  954. */
  955. /*
  956. * Attempt to get the fixed panel mode from DDC. Assume that the
  957. * preferred mode is the right one.
  958. */
  959. mutex_lock(&dev->mode_config.mutex);
  960. if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC)
  961. edid = drm_get_edid_switcheroo(connector,
  962. intel_gmbus_get_adapter(dev_priv, pin));
  963. else
  964. edid = drm_get_edid(connector,
  965. intel_gmbus_get_adapter(dev_priv, pin));
  966. if (edid) {
  967. if (drm_add_edid_modes(connector, edid)) {
  968. drm_mode_connector_update_edid_property(connector,
  969. edid);
  970. } else {
  971. kfree(edid);
  972. edid = ERR_PTR(-EINVAL);
  973. }
  974. } else {
  975. edid = ERR_PTR(-ENOENT);
  976. }
  977. lvds_connector->base.edid = edid;
  978. if (IS_ERR_OR_NULL(edid)) {
  979. /* Didn't get an EDID, so
  980. * Set wide sync ranges so we get all modes
  981. * handed to valid_mode for checking
  982. */
  983. connector->display_info.min_vfreq = 0;
  984. connector->display_info.max_vfreq = 200;
  985. connector->display_info.min_hfreq = 0;
  986. connector->display_info.max_hfreq = 200;
  987. }
  988. list_for_each_entry(scan, &connector->probed_modes, head) {
  989. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  990. DRM_DEBUG_KMS("using preferred mode from EDID: ");
  991. drm_mode_debug_printmodeline(scan);
  992. fixed_mode = drm_mode_duplicate(dev, scan);
  993. if (fixed_mode)
  994. goto out;
  995. }
  996. }
  997. /* Failed to get EDID, what about VBT? */
  998. if (dev_priv->vbt.lfp_lvds_vbt_mode) {
  999. DRM_DEBUG_KMS("using mode from VBT: ");
  1000. drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
  1001. fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
  1002. if (fixed_mode) {
  1003. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1004. connector->display_info.width_mm = fixed_mode->width_mm;
  1005. connector->display_info.height_mm = fixed_mode->height_mm;
  1006. goto out;
  1007. }
  1008. }
  1009. /*
  1010. * If we didn't get EDID, try checking if the panel is already turned
  1011. * on. If so, assume that whatever is currently programmed is the
  1012. * correct mode.
  1013. */
  1014. /* Ironlake: FIXME if still fail, not try pipe mode now */
  1015. if (HAS_PCH_SPLIT(dev))
  1016. goto failed;
  1017. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  1018. crtc = intel_get_crtc_for_pipe(dev, pipe);
  1019. if (crtc && (lvds & LVDS_PORT_EN)) {
  1020. fixed_mode = intel_crtc_mode_get(dev, crtc);
  1021. if (fixed_mode) {
  1022. DRM_DEBUG_KMS("using current (BIOS) mode: ");
  1023. drm_mode_debug_printmodeline(fixed_mode);
  1024. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1025. goto out;
  1026. }
  1027. }
  1028. /* If we still don't have a mode after all that, give up. */
  1029. if (!fixed_mode)
  1030. goto failed;
  1031. out:
  1032. mutex_unlock(&dev->mode_config.mutex);
  1033. intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
  1034. intel_panel_setup_backlight(connector, INVALID_PIPE);
  1035. lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
  1036. DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
  1037. lvds_encoder->is_dual_link ? "dual" : "single");
  1038. lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK;
  1039. lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
  1040. if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
  1041. DRM_DEBUG_KMS("lid notifier registration failed\n");
  1042. lvds_connector->lid_notifier.notifier_call = NULL;
  1043. }
  1044. return;
  1045. failed:
  1046. mutex_unlock(&dev->mode_config.mutex);
  1047. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  1048. drm_connector_cleanup(connector);
  1049. drm_encoder_cleanup(encoder);
  1050. kfree(lvds_encoder);
  1051. kfree(lvds_connector);
  1052. return;
  1053. }