intel_lvds.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors:
  25. * Eric Anholt <eric@anholt.net>
  26. * Dave Airlie <airlied@linux.ie>
  27. * Jesse Barnes <jesse.barnes@intel.com>
  28. */
  29. #include <acpi/button.h>
  30. #include <linux/dmi.h>
  31. #include <linux/i2c.h>
  32. #include <linux/slab.h>
  33. #include <linux/vga_switcheroo.h>
  34. #include <drm/drmP.h>
  35. #include <drm/drm_atomic_helper.h>
  36. #include <drm/drm_crtc.h>
  37. #include <drm/drm_edid.h>
  38. #include "intel_drv.h"
  39. #include <drm/i915_drm.h>
  40. #include "i915_drv.h"
  41. #include <linux/acpi.h>
  42. /* Private structure for the integrated LVDS support */
  43. struct intel_lvds_connector {
  44. struct intel_connector base;
  45. };
  46. struct intel_lvds_pps {
  47. /* 100us units */
  48. int t1_t2;
  49. int t3;
  50. int t4;
  51. int t5;
  52. int tx;
  53. int divider;
  54. int port;
  55. bool powerdown_on_reset;
  56. };
  57. struct intel_lvds_encoder {
  58. struct intel_encoder base;
  59. bool is_dual_link;
  60. i915_reg_t reg;
  61. u32 a3_power;
  62. struct intel_lvds_pps init_pps;
  63. u32 init_lvds_val;
  64. struct intel_lvds_connector *attached_connector;
  65. };
  66. static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
  67. {
  68. return container_of(encoder, struct intel_lvds_encoder, base.base);
  69. }
  70. static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
  71. {
  72. return container_of(connector, struct intel_lvds_connector, base.base);
  73. }
  74. bool intel_lvds_port_enabled(struct drm_i915_private *dev_priv,
  75. i915_reg_t lvds_reg, enum pipe *pipe)
  76. {
  77. u32 val;
  78. val = I915_READ(lvds_reg);
  79. /* asserts want to know the pipe even if the port is disabled */
  80. if (HAS_PCH_CPT(dev_priv))
  81. *pipe = (val & LVDS_PIPE_SEL_MASK_CPT) >> LVDS_PIPE_SEL_SHIFT_CPT;
  82. else
  83. *pipe = (val & LVDS_PIPE_SEL_MASK) >> LVDS_PIPE_SEL_SHIFT;
  84. return val & LVDS_PORT_EN;
  85. }
  86. static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
  87. enum pipe *pipe)
  88. {
  89. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  90. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  91. bool ret;
  92. if (!intel_display_power_get_if_enabled(dev_priv,
  93. encoder->power_domain))
  94. return false;
  95. ret = intel_lvds_port_enabled(dev_priv, lvds_encoder->reg, pipe);
  96. intel_display_power_put(dev_priv, encoder->power_domain);
  97. return ret;
  98. }
  99. static void intel_lvds_get_config(struct intel_encoder *encoder,
  100. struct intel_crtc_state *pipe_config)
  101. {
  102. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  103. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  104. u32 tmp, flags = 0;
  105. pipe_config->output_types |= BIT(INTEL_OUTPUT_LVDS);
  106. tmp = I915_READ(lvds_encoder->reg);
  107. if (tmp & LVDS_HSYNC_POLARITY)
  108. flags |= DRM_MODE_FLAG_NHSYNC;
  109. else
  110. flags |= DRM_MODE_FLAG_PHSYNC;
  111. if (tmp & LVDS_VSYNC_POLARITY)
  112. flags |= DRM_MODE_FLAG_NVSYNC;
  113. else
  114. flags |= DRM_MODE_FLAG_PVSYNC;
  115. pipe_config->base.adjusted_mode.flags |= flags;
  116. if (INTEL_GEN(dev_priv) < 5)
  117. pipe_config->gmch_pfit.lvds_border_bits =
  118. tmp & LVDS_BORDER_ENABLE;
  119. /* gen2/3 store dither state in pfit control, needs to match */
  120. if (INTEL_GEN(dev_priv) < 4) {
  121. tmp = I915_READ(PFIT_CONTROL);
  122. pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
  123. }
  124. pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
  125. }
  126. static void intel_lvds_pps_get_hw_state(struct drm_i915_private *dev_priv,
  127. struct intel_lvds_pps *pps)
  128. {
  129. u32 val;
  130. pps->powerdown_on_reset = I915_READ(PP_CONTROL(0)) & PANEL_POWER_RESET;
  131. val = I915_READ(PP_ON_DELAYS(0));
  132. pps->port = (val & PANEL_PORT_SELECT_MASK) >>
  133. PANEL_PORT_SELECT_SHIFT;
  134. pps->t1_t2 = (val & PANEL_POWER_UP_DELAY_MASK) >>
  135. PANEL_POWER_UP_DELAY_SHIFT;
  136. pps->t5 = (val & PANEL_LIGHT_ON_DELAY_MASK) >>
  137. PANEL_LIGHT_ON_DELAY_SHIFT;
  138. val = I915_READ(PP_OFF_DELAYS(0));
  139. pps->t3 = (val & PANEL_POWER_DOWN_DELAY_MASK) >>
  140. PANEL_POWER_DOWN_DELAY_SHIFT;
  141. pps->tx = (val & PANEL_LIGHT_OFF_DELAY_MASK) >>
  142. PANEL_LIGHT_OFF_DELAY_SHIFT;
  143. val = I915_READ(PP_DIVISOR(0));
  144. pps->divider = (val & PP_REFERENCE_DIVIDER_MASK) >>
  145. PP_REFERENCE_DIVIDER_SHIFT;
  146. val = (val & PANEL_POWER_CYCLE_DELAY_MASK) >>
  147. PANEL_POWER_CYCLE_DELAY_SHIFT;
  148. /*
  149. * Remove the BSpec specified +1 (100ms) offset that accounts for a
  150. * too short power-cycle delay due to the asynchronous programming of
  151. * the register.
  152. */
  153. if (val)
  154. val--;
  155. /* Convert from 100ms to 100us units */
  156. pps->t4 = val * 1000;
  157. if (INTEL_GEN(dev_priv) <= 4 &&
  158. pps->t1_t2 == 0 && pps->t5 == 0 && pps->t3 == 0 && pps->tx == 0) {
  159. DRM_DEBUG_KMS("Panel power timings uninitialized, "
  160. "setting defaults\n");
  161. /* Set T2 to 40ms and T5 to 200ms in 100 usec units */
  162. pps->t1_t2 = 40 * 10;
  163. pps->t5 = 200 * 10;
  164. /* Set T3 to 35ms and Tx to 200ms in 100 usec units */
  165. pps->t3 = 35 * 10;
  166. pps->tx = 200 * 10;
  167. }
  168. DRM_DEBUG_DRIVER("LVDS PPS:t1+t2 %d t3 %d t4 %d t5 %d tx %d "
  169. "divider %d port %d powerdown_on_reset %d\n",
  170. pps->t1_t2, pps->t3, pps->t4, pps->t5, pps->tx,
  171. pps->divider, pps->port, pps->powerdown_on_reset);
  172. }
  173. static void intel_lvds_pps_init_hw(struct drm_i915_private *dev_priv,
  174. struct intel_lvds_pps *pps)
  175. {
  176. u32 val;
  177. val = I915_READ(PP_CONTROL(0));
  178. WARN_ON((val & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS);
  179. if (pps->powerdown_on_reset)
  180. val |= PANEL_POWER_RESET;
  181. I915_WRITE(PP_CONTROL(0), val);
  182. I915_WRITE(PP_ON_DELAYS(0), (pps->port << PANEL_PORT_SELECT_SHIFT) |
  183. (pps->t1_t2 << PANEL_POWER_UP_DELAY_SHIFT) |
  184. (pps->t5 << PANEL_LIGHT_ON_DELAY_SHIFT));
  185. I915_WRITE(PP_OFF_DELAYS(0), (pps->t3 << PANEL_POWER_DOWN_DELAY_SHIFT) |
  186. (pps->tx << PANEL_LIGHT_OFF_DELAY_SHIFT));
  187. val = pps->divider << PP_REFERENCE_DIVIDER_SHIFT;
  188. val |= (DIV_ROUND_UP(pps->t4, 1000) + 1) <<
  189. PANEL_POWER_CYCLE_DELAY_SHIFT;
  190. I915_WRITE(PP_DIVISOR(0), val);
  191. }
  192. static void intel_pre_enable_lvds(struct intel_encoder *encoder,
  193. const struct intel_crtc_state *pipe_config,
  194. const struct drm_connector_state *conn_state)
  195. {
  196. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  197. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  198. struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  199. const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  200. int pipe = crtc->pipe;
  201. u32 temp;
  202. if (HAS_PCH_SPLIT(dev_priv)) {
  203. assert_fdi_rx_pll_disabled(dev_priv, pipe);
  204. assert_shared_dpll_disabled(dev_priv,
  205. pipe_config->shared_dpll);
  206. } else {
  207. assert_pll_disabled(dev_priv, pipe);
  208. }
  209. intel_lvds_pps_init_hw(dev_priv, &lvds_encoder->init_pps);
  210. temp = lvds_encoder->init_lvds_val;
  211. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  212. if (HAS_PCH_CPT(dev_priv)) {
  213. temp &= ~LVDS_PIPE_SEL_MASK_CPT;
  214. temp |= LVDS_PIPE_SEL_CPT(pipe);
  215. } else {
  216. temp &= ~LVDS_PIPE_SEL_MASK;
  217. temp |= LVDS_PIPE_SEL(pipe);
  218. }
  219. /* set the corresponsding LVDS_BORDER bit */
  220. temp &= ~LVDS_BORDER_ENABLE;
  221. temp |= pipe_config->gmch_pfit.lvds_border_bits;
  222. /*
  223. * Set the B0-B3 data pairs corresponding to whether we're going to
  224. * set the DPLLs for dual-channel mode or not.
  225. */
  226. if (lvds_encoder->is_dual_link)
  227. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  228. else
  229. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  230. /*
  231. * It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  232. * appropriately here, but we need to look more thoroughly into how
  233. * panels behave in the two modes. For now, let's just maintain the
  234. * value we got from the BIOS.
  235. */
  236. temp &= ~LVDS_A3_POWER_MASK;
  237. temp |= lvds_encoder->a3_power;
  238. /*
  239. * Set the dithering flag on LVDS as needed, note that there is no
  240. * special lvds dither control bit on pch-split platforms, dithering is
  241. * only controlled through the PIPECONF reg.
  242. */
  243. if (IS_GEN4(dev_priv)) {
  244. /*
  245. * Bspec wording suggests that LVDS port dithering only exists
  246. * for 18bpp panels.
  247. */
  248. if (pipe_config->dither && pipe_config->pipe_bpp == 18)
  249. temp |= LVDS_ENABLE_DITHER;
  250. else
  251. temp &= ~LVDS_ENABLE_DITHER;
  252. }
  253. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  254. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  255. temp |= LVDS_HSYNC_POLARITY;
  256. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  257. temp |= LVDS_VSYNC_POLARITY;
  258. I915_WRITE(lvds_encoder->reg, temp);
  259. }
  260. /*
  261. * Sets the power state for the panel.
  262. */
  263. static void intel_enable_lvds(struct intel_encoder *encoder,
  264. const struct intel_crtc_state *pipe_config,
  265. const struct drm_connector_state *conn_state)
  266. {
  267. struct drm_device *dev = encoder->base.dev;
  268. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  269. struct drm_i915_private *dev_priv = to_i915(dev);
  270. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
  271. I915_WRITE(PP_CONTROL(0), I915_READ(PP_CONTROL(0)) | PANEL_POWER_ON);
  272. POSTING_READ(lvds_encoder->reg);
  273. if (intel_wait_for_register(dev_priv, PP_STATUS(0), PP_ON, PP_ON, 5000))
  274. DRM_ERROR("timed out waiting for panel to power on\n");
  275. intel_panel_enable_backlight(pipe_config, conn_state);
  276. }
  277. static void intel_disable_lvds(struct intel_encoder *encoder,
  278. const struct intel_crtc_state *old_crtc_state,
  279. const struct drm_connector_state *old_conn_state)
  280. {
  281. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  282. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  283. I915_WRITE(PP_CONTROL(0), I915_READ(PP_CONTROL(0)) & ~PANEL_POWER_ON);
  284. if (intel_wait_for_register(dev_priv, PP_STATUS(0), PP_ON, 0, 1000))
  285. DRM_ERROR("timed out waiting for panel to power off\n");
  286. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
  287. POSTING_READ(lvds_encoder->reg);
  288. }
  289. static void gmch_disable_lvds(struct intel_encoder *encoder,
  290. const struct intel_crtc_state *old_crtc_state,
  291. const struct drm_connector_state *old_conn_state)
  292. {
  293. intel_panel_disable_backlight(old_conn_state);
  294. intel_disable_lvds(encoder, old_crtc_state, old_conn_state);
  295. }
  296. static void pch_disable_lvds(struct intel_encoder *encoder,
  297. const struct intel_crtc_state *old_crtc_state,
  298. const struct drm_connector_state *old_conn_state)
  299. {
  300. intel_panel_disable_backlight(old_conn_state);
  301. }
  302. static void pch_post_disable_lvds(struct intel_encoder *encoder,
  303. const struct intel_crtc_state *old_crtc_state,
  304. const struct drm_connector_state *old_conn_state)
  305. {
  306. intel_disable_lvds(encoder, old_crtc_state, old_conn_state);
  307. }
  308. static enum drm_mode_status
  309. intel_lvds_mode_valid(struct drm_connector *connector,
  310. struct drm_display_mode *mode)
  311. {
  312. struct intel_connector *intel_connector = to_intel_connector(connector);
  313. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  314. int max_pixclk = to_i915(connector->dev)->max_dotclk_freq;
  315. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  316. return MODE_NO_DBLESCAN;
  317. if (mode->hdisplay > fixed_mode->hdisplay)
  318. return MODE_PANEL;
  319. if (mode->vdisplay > fixed_mode->vdisplay)
  320. return MODE_PANEL;
  321. if (fixed_mode->clock > max_pixclk)
  322. return MODE_CLOCK_HIGH;
  323. return MODE_OK;
  324. }
  325. static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
  326. struct intel_crtc_state *pipe_config,
  327. struct drm_connector_state *conn_state)
  328. {
  329. struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
  330. struct intel_lvds_encoder *lvds_encoder =
  331. to_lvds_encoder(&intel_encoder->base);
  332. struct intel_connector *intel_connector =
  333. &lvds_encoder->attached_connector->base;
  334. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  335. struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
  336. unsigned int lvds_bpp;
  337. /* Should never happen!! */
  338. if (INTEL_GEN(dev_priv) < 4 && intel_crtc->pipe == 0) {
  339. DRM_ERROR("Can't support LVDS on pipe A\n");
  340. return false;
  341. }
  342. if (lvds_encoder->a3_power == LVDS_A3_POWER_UP)
  343. lvds_bpp = 8*3;
  344. else
  345. lvds_bpp = 6*3;
  346. if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
  347. DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
  348. pipe_config->pipe_bpp, lvds_bpp);
  349. pipe_config->pipe_bpp = lvds_bpp;
  350. }
  351. /*
  352. * We have timings from the BIOS for the panel, put them in
  353. * to the adjusted mode. The CRTC will be set up for this mode,
  354. * with the panel scaling set up to source from the H/VDisplay
  355. * of the original mode.
  356. */
  357. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  358. adjusted_mode);
  359. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
  360. return false;
  361. if (HAS_PCH_SPLIT(dev_priv)) {
  362. pipe_config->has_pch_encoder = true;
  363. intel_pch_panel_fitting(intel_crtc, pipe_config,
  364. conn_state->scaling_mode);
  365. } else {
  366. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  367. conn_state->scaling_mode);
  368. }
  369. /*
  370. * XXX: It would be nice to support lower refresh rates on the
  371. * panels to reduce power consumption, and perhaps match the
  372. * user's requested refresh rate.
  373. */
  374. return true;
  375. }
  376. static enum drm_connector_status
  377. intel_lvds_detect(struct drm_connector *connector, bool force)
  378. {
  379. return connector_status_connected;
  380. }
  381. /*
  382. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  383. */
  384. static int intel_lvds_get_modes(struct drm_connector *connector)
  385. {
  386. struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
  387. struct drm_device *dev = connector->dev;
  388. struct drm_display_mode *mode;
  389. /* use cached edid if we have one */
  390. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  391. return drm_add_edid_modes(connector, lvds_connector->base.edid);
  392. mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
  393. if (mode == NULL)
  394. return 0;
  395. drm_mode_probed_add(connector, mode);
  396. return 1;
  397. }
  398. /**
  399. * intel_lvds_destroy - unregister and free LVDS structures
  400. * @connector: connector to free
  401. *
  402. * Unregister the DDC bus for this connector then free the driver private
  403. * structure.
  404. */
  405. static void intel_lvds_destroy(struct drm_connector *connector)
  406. {
  407. struct intel_lvds_connector *lvds_connector =
  408. to_lvds_connector(connector);
  409. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  410. kfree(lvds_connector->base.edid);
  411. intel_panel_fini(&lvds_connector->base.panel);
  412. drm_connector_cleanup(connector);
  413. kfree(connector);
  414. }
  415. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  416. .get_modes = intel_lvds_get_modes,
  417. .mode_valid = intel_lvds_mode_valid,
  418. .atomic_check = intel_digital_connector_atomic_check,
  419. };
  420. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  421. .detect = intel_lvds_detect,
  422. .fill_modes = drm_helper_probe_single_connector_modes,
  423. .atomic_get_property = intel_digital_connector_atomic_get_property,
  424. .atomic_set_property = intel_digital_connector_atomic_set_property,
  425. .late_register = intel_connector_register,
  426. .early_unregister = intel_connector_unregister,
  427. .destroy = intel_lvds_destroy,
  428. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  429. .atomic_duplicate_state = intel_digital_connector_duplicate_state,
  430. };
  431. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  432. .destroy = intel_encoder_destroy,
  433. };
  434. static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  435. {
  436. DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
  437. return 1;
  438. }
  439. /* These systems claim to have LVDS, but really don't */
  440. static const struct dmi_system_id intel_no_lvds[] = {
  441. {
  442. .callback = intel_no_lvds_dmi_callback,
  443. .ident = "Apple Mac Mini (Core series)",
  444. .matches = {
  445. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  446. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  447. },
  448. },
  449. {
  450. .callback = intel_no_lvds_dmi_callback,
  451. .ident = "Apple Mac Mini (Core 2 series)",
  452. .matches = {
  453. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  454. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  455. },
  456. },
  457. {
  458. .callback = intel_no_lvds_dmi_callback,
  459. .ident = "MSI IM-945GSE-A",
  460. .matches = {
  461. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  462. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  463. },
  464. },
  465. {
  466. .callback = intel_no_lvds_dmi_callback,
  467. .ident = "Dell Studio Hybrid",
  468. .matches = {
  469. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  470. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  471. },
  472. },
  473. {
  474. .callback = intel_no_lvds_dmi_callback,
  475. .ident = "Dell OptiPlex FX170",
  476. .matches = {
  477. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  478. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
  479. },
  480. },
  481. {
  482. .callback = intel_no_lvds_dmi_callback,
  483. .ident = "AOpen Mini PC",
  484. .matches = {
  485. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  486. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  487. },
  488. },
  489. {
  490. .callback = intel_no_lvds_dmi_callback,
  491. .ident = "AOpen Mini PC MP915",
  492. .matches = {
  493. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  494. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  495. },
  496. },
  497. {
  498. .callback = intel_no_lvds_dmi_callback,
  499. .ident = "AOpen i915GMm-HFS",
  500. .matches = {
  501. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  502. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  503. },
  504. },
  505. {
  506. .callback = intel_no_lvds_dmi_callback,
  507. .ident = "AOpen i45GMx-I",
  508. .matches = {
  509. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  510. DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
  511. },
  512. },
  513. {
  514. .callback = intel_no_lvds_dmi_callback,
  515. .ident = "Aopen i945GTt-VFA",
  516. .matches = {
  517. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  518. },
  519. },
  520. {
  521. .callback = intel_no_lvds_dmi_callback,
  522. .ident = "Clientron U800",
  523. .matches = {
  524. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  525. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  526. },
  527. },
  528. {
  529. .callback = intel_no_lvds_dmi_callback,
  530. .ident = "Clientron E830",
  531. .matches = {
  532. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  533. DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
  534. },
  535. },
  536. {
  537. .callback = intel_no_lvds_dmi_callback,
  538. .ident = "Asus EeeBox PC EB1007",
  539. .matches = {
  540. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  541. DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
  542. },
  543. },
  544. {
  545. .callback = intel_no_lvds_dmi_callback,
  546. .ident = "Asus AT5NM10T-I",
  547. .matches = {
  548. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  549. DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
  550. },
  551. },
  552. {
  553. .callback = intel_no_lvds_dmi_callback,
  554. .ident = "Hewlett-Packard HP t5740",
  555. .matches = {
  556. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  557. DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
  558. },
  559. },
  560. {
  561. .callback = intel_no_lvds_dmi_callback,
  562. .ident = "Hewlett-Packard t5745",
  563. .matches = {
  564. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  565. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
  566. },
  567. },
  568. {
  569. .callback = intel_no_lvds_dmi_callback,
  570. .ident = "Hewlett-Packard st5747",
  571. .matches = {
  572. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  573. DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
  574. },
  575. },
  576. {
  577. .callback = intel_no_lvds_dmi_callback,
  578. .ident = "MSI Wind Box DC500",
  579. .matches = {
  580. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  581. DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
  582. },
  583. },
  584. {
  585. .callback = intel_no_lvds_dmi_callback,
  586. .ident = "Gigabyte GA-D525TUD",
  587. .matches = {
  588. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  589. DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
  590. },
  591. },
  592. {
  593. .callback = intel_no_lvds_dmi_callback,
  594. .ident = "Supermicro X7SPA-H",
  595. .matches = {
  596. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  597. DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
  598. },
  599. },
  600. {
  601. .callback = intel_no_lvds_dmi_callback,
  602. .ident = "Fujitsu Esprimo Q900",
  603. .matches = {
  604. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  605. DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
  606. },
  607. },
  608. {
  609. .callback = intel_no_lvds_dmi_callback,
  610. .ident = "Intel D410PT",
  611. .matches = {
  612. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  613. DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
  614. },
  615. },
  616. {
  617. .callback = intel_no_lvds_dmi_callback,
  618. .ident = "Intel D425KT",
  619. .matches = {
  620. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  621. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
  622. },
  623. },
  624. {
  625. .callback = intel_no_lvds_dmi_callback,
  626. .ident = "Intel D510MO",
  627. .matches = {
  628. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  629. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
  630. },
  631. },
  632. {
  633. .callback = intel_no_lvds_dmi_callback,
  634. .ident = "Intel D525MW",
  635. .matches = {
  636. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  637. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
  638. },
  639. },
  640. {
  641. .callback = intel_no_lvds_dmi_callback,
  642. .ident = "Radiant P845",
  643. .matches = {
  644. DMI_MATCH(DMI_SYS_VENDOR, "Radiant Systems Inc"),
  645. DMI_MATCH(DMI_PRODUCT_NAME, "P845"),
  646. },
  647. },
  648. { } /* terminating entry */
  649. };
  650. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  651. {
  652. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  653. return 1;
  654. }
  655. static const struct dmi_system_id intel_dual_link_lvds[] = {
  656. {
  657. .callback = intel_dual_link_lvds_callback,
  658. .ident = "Apple MacBook Pro 15\" (2010)",
  659. .matches = {
  660. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  661. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
  662. },
  663. },
  664. {
  665. .callback = intel_dual_link_lvds_callback,
  666. .ident = "Apple MacBook Pro 15\" (2011)",
  667. .matches = {
  668. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  669. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  670. },
  671. },
  672. {
  673. .callback = intel_dual_link_lvds_callback,
  674. .ident = "Apple MacBook Pro 15\" (2012)",
  675. .matches = {
  676. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  677. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
  678. },
  679. },
  680. { } /* terminating entry */
  681. };
  682. struct intel_encoder *intel_get_lvds_encoder(struct drm_device *dev)
  683. {
  684. struct intel_encoder *intel_encoder;
  685. for_each_intel_encoder(dev, intel_encoder)
  686. if (intel_encoder->type == INTEL_OUTPUT_LVDS)
  687. return intel_encoder;
  688. return NULL;
  689. }
  690. bool intel_is_dual_link_lvds(struct drm_device *dev)
  691. {
  692. struct intel_encoder *encoder = intel_get_lvds_encoder(dev);
  693. return encoder && to_lvds_encoder(&encoder->base)->is_dual_link;
  694. }
  695. static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
  696. {
  697. struct drm_device *dev = lvds_encoder->base.base.dev;
  698. unsigned int val;
  699. struct drm_i915_private *dev_priv = to_i915(dev);
  700. /* use the module option value if specified */
  701. if (i915_modparams.lvds_channel_mode > 0)
  702. return i915_modparams.lvds_channel_mode == 2;
  703. /* single channel LVDS is limited to 112 MHz */
  704. if (lvds_encoder->attached_connector->base.panel.fixed_mode->clock
  705. > 112999)
  706. return true;
  707. if (dmi_check_system(intel_dual_link_lvds))
  708. return true;
  709. /*
  710. * BIOS should set the proper LVDS register value at boot, but
  711. * in reality, it doesn't set the value when the lid is closed;
  712. * we need to check "the value to be set" in VBT when LVDS
  713. * register is uninitialized.
  714. */
  715. val = I915_READ(lvds_encoder->reg);
  716. if (HAS_PCH_CPT(dev_priv))
  717. val &= ~(LVDS_DETECTED | LVDS_PIPE_SEL_MASK_CPT);
  718. else
  719. val &= ~(LVDS_DETECTED | LVDS_PIPE_SEL_MASK);
  720. if (val == 0)
  721. val = dev_priv->vbt.bios_lvds_val;
  722. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  723. }
  724. static bool intel_lvds_supported(struct drm_i915_private *dev_priv)
  725. {
  726. /*
  727. * With the introduction of the PCH we gained a dedicated
  728. * LVDS presence pin, use it.
  729. */
  730. if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
  731. return true;
  732. /*
  733. * Otherwise LVDS was only attached to mobile products,
  734. * except for the inglorious 830gm
  735. */
  736. if (INTEL_GEN(dev_priv) <= 4 &&
  737. IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
  738. return true;
  739. return false;
  740. }
  741. /**
  742. * intel_lvds_init - setup LVDS connectors on this device
  743. * @dev_priv: i915 device
  744. *
  745. * Create the connector, register the LVDS DDC bus, and try to figure out what
  746. * modes we can display on the LVDS panel (if present).
  747. */
  748. void intel_lvds_init(struct drm_i915_private *dev_priv)
  749. {
  750. struct drm_device *dev = &dev_priv->drm;
  751. struct intel_lvds_encoder *lvds_encoder;
  752. struct intel_encoder *intel_encoder;
  753. struct intel_lvds_connector *lvds_connector;
  754. struct intel_connector *intel_connector;
  755. struct drm_connector *connector;
  756. struct drm_encoder *encoder;
  757. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  758. struct drm_display_mode *fixed_mode = NULL;
  759. struct drm_display_mode *downclock_mode = NULL;
  760. struct edid *edid;
  761. i915_reg_t lvds_reg;
  762. u32 lvds;
  763. u8 pin;
  764. u32 allowed_scalers;
  765. if (!intel_lvds_supported(dev_priv))
  766. return;
  767. /* Skip init on machines we know falsely report LVDS */
  768. if (dmi_check_system(intel_no_lvds)) {
  769. WARN(!dev_priv->vbt.int_lvds_support,
  770. "Useless DMI match. Internal LVDS support disabled by VBT\n");
  771. return;
  772. }
  773. if (!dev_priv->vbt.int_lvds_support) {
  774. DRM_DEBUG_KMS("Internal LVDS support disabled by VBT\n");
  775. return;
  776. }
  777. if (HAS_PCH_SPLIT(dev_priv))
  778. lvds_reg = PCH_LVDS;
  779. else
  780. lvds_reg = LVDS;
  781. lvds = I915_READ(lvds_reg);
  782. if (HAS_PCH_SPLIT(dev_priv)) {
  783. if ((lvds & LVDS_DETECTED) == 0)
  784. return;
  785. }
  786. pin = GMBUS_PIN_PANEL;
  787. if (!intel_bios_is_lvds_present(dev_priv, &pin)) {
  788. if ((lvds & LVDS_PORT_EN) == 0) {
  789. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  790. return;
  791. }
  792. DRM_DEBUG_KMS("LVDS is not present in VBT, but enabled anyway\n");
  793. }
  794. lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
  795. if (!lvds_encoder)
  796. return;
  797. lvds_connector = kzalloc(sizeof(*lvds_connector), GFP_KERNEL);
  798. if (!lvds_connector) {
  799. kfree(lvds_encoder);
  800. return;
  801. }
  802. if (intel_connector_init(&lvds_connector->base) < 0) {
  803. kfree(lvds_connector);
  804. kfree(lvds_encoder);
  805. return;
  806. }
  807. lvds_encoder->attached_connector = lvds_connector;
  808. intel_encoder = &lvds_encoder->base;
  809. encoder = &intel_encoder->base;
  810. intel_connector = &lvds_connector->base;
  811. connector = &intel_connector->base;
  812. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  813. DRM_MODE_CONNECTOR_LVDS);
  814. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  815. DRM_MODE_ENCODER_LVDS, "LVDS");
  816. intel_encoder->enable = intel_enable_lvds;
  817. intel_encoder->pre_enable = intel_pre_enable_lvds;
  818. intel_encoder->compute_config = intel_lvds_compute_config;
  819. if (HAS_PCH_SPLIT(dev_priv)) {
  820. intel_encoder->disable = pch_disable_lvds;
  821. intel_encoder->post_disable = pch_post_disable_lvds;
  822. } else {
  823. intel_encoder->disable = gmch_disable_lvds;
  824. }
  825. intel_encoder->get_hw_state = intel_lvds_get_hw_state;
  826. intel_encoder->get_config = intel_lvds_get_config;
  827. intel_connector->get_hw_state = intel_connector_get_hw_state;
  828. intel_connector_attach_encoder(intel_connector, intel_encoder);
  829. intel_encoder->type = INTEL_OUTPUT_LVDS;
  830. intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER;
  831. intel_encoder->port = PORT_NONE;
  832. intel_encoder->cloneable = 0;
  833. if (HAS_PCH_SPLIT(dev_priv))
  834. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  835. else if (IS_GEN4(dev_priv))
  836. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  837. else
  838. intel_encoder->crtc_mask = (1 << 1);
  839. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  840. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  841. connector->interlace_allowed = false;
  842. connector->doublescan_allowed = false;
  843. lvds_encoder->reg = lvds_reg;
  844. /* create the scaling mode property */
  845. allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT);
  846. allowed_scalers |= BIT(DRM_MODE_SCALE_FULLSCREEN);
  847. allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
  848. drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
  849. connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
  850. intel_lvds_pps_get_hw_state(dev_priv, &lvds_encoder->init_pps);
  851. lvds_encoder->init_lvds_val = lvds;
  852. /*
  853. * LVDS discovery:
  854. * 1) check for EDID on DDC
  855. * 2) check for VBT data
  856. * 3) check to see if LVDS is already on
  857. * if none of the above, no panel
  858. */
  859. /*
  860. * Attempt to get the fixed panel mode from DDC. Assume that the
  861. * preferred mode is the right one.
  862. */
  863. mutex_lock(&dev->mode_config.mutex);
  864. if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC)
  865. edid = drm_get_edid_switcheroo(connector,
  866. intel_gmbus_get_adapter(dev_priv, pin));
  867. else
  868. edid = drm_get_edid(connector,
  869. intel_gmbus_get_adapter(dev_priv, pin));
  870. if (edid) {
  871. if (drm_add_edid_modes(connector, edid)) {
  872. drm_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. list_for_each_entry(scan, &connector->probed_modes, head) {
  883. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  884. DRM_DEBUG_KMS("using preferred mode from EDID: ");
  885. drm_mode_debug_printmodeline(scan);
  886. fixed_mode = drm_mode_duplicate(dev, scan);
  887. if (fixed_mode)
  888. goto out;
  889. }
  890. }
  891. /* Failed to get EDID, what about VBT? */
  892. if (dev_priv->vbt.lfp_lvds_vbt_mode) {
  893. DRM_DEBUG_KMS("using mode from VBT: ");
  894. drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
  895. fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
  896. if (fixed_mode) {
  897. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  898. connector->display_info.width_mm = fixed_mode->width_mm;
  899. connector->display_info.height_mm = fixed_mode->height_mm;
  900. goto out;
  901. }
  902. }
  903. /*
  904. * If we didn't get EDID, try checking if the panel is already turned
  905. * on. If so, assume that whatever is currently programmed is the
  906. * correct mode.
  907. */
  908. fixed_mode = intel_encoder_current_mode(intel_encoder);
  909. if (fixed_mode) {
  910. DRM_DEBUG_KMS("using current (BIOS) mode: ");
  911. drm_mode_debug_printmodeline(fixed_mode);
  912. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  913. }
  914. /* If we still don't have a mode after all that, give up. */
  915. if (!fixed_mode)
  916. goto failed;
  917. out:
  918. mutex_unlock(&dev->mode_config.mutex);
  919. intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
  920. intel_panel_setup_backlight(connector, INVALID_PIPE);
  921. lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
  922. DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
  923. lvds_encoder->is_dual_link ? "dual" : "single");
  924. lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK;
  925. return;
  926. failed:
  927. mutex_unlock(&dev->mode_config.mutex);
  928. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  929. drm_connector_cleanup(connector);
  930. drm_encoder_cleanup(encoder);
  931. kfree(lvds_encoder);
  932. kfree(lvds_connector);
  933. return;
  934. }