intel_lvds.c 37 KB

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