intel_lvds.c 31 KB

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