intel_lvds.c 33 KB

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