intel_lvds.c 34 KB

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