intel_lvds.c 32 KB

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