intel_lvds.c 32 KB

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