intel_lvds.c 37 KB

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