intel_lvds.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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 "drmP.h"
  34. #include "drm.h"
  35. #include "drm_crtc.h"
  36. #include "drm_edid.h"
  37. #include "intel_drv.h"
  38. #include "i915_drm.h"
  39. #include "i915_drv.h"
  40. #include <linux/acpi.h>
  41. /* Private structure for the integrated LVDS support */
  42. struct intel_lvds {
  43. struct intel_encoder base;
  44. int fitting_mode;
  45. u32 pfit_control;
  46. u32 pfit_pgm_ratios;
  47. };
  48. static struct intel_lvds *enc_to_intel_lvds(struct drm_encoder *encoder)
  49. {
  50. return container_of(enc_to_intel_encoder(encoder), struct intel_lvds, base);
  51. }
  52. /**
  53. * Sets the backlight level.
  54. *
  55. * \param level backlight level, from 0 to intel_lvds_get_max_backlight().
  56. */
  57. static void intel_lvds_set_backlight(struct drm_device *dev, int level)
  58. {
  59. struct drm_i915_private *dev_priv = dev->dev_private;
  60. u32 blc_pwm_ctl, reg;
  61. if (HAS_PCH_SPLIT(dev))
  62. reg = BLC_PWM_CPU_CTL;
  63. else
  64. reg = BLC_PWM_CTL;
  65. blc_pwm_ctl = I915_READ(reg) & ~BACKLIGHT_DUTY_CYCLE_MASK;
  66. I915_WRITE(reg, (blc_pwm_ctl |
  67. (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
  68. }
  69. /**
  70. * Returns the maximum level of the backlight duty cycle field.
  71. */
  72. static u32 intel_lvds_get_max_backlight(struct drm_device *dev)
  73. {
  74. struct drm_i915_private *dev_priv = dev->dev_private;
  75. u32 reg;
  76. if (HAS_PCH_SPLIT(dev))
  77. reg = BLC_PWM_PCH_CTL2;
  78. else
  79. reg = BLC_PWM_CTL;
  80. return ((I915_READ(reg) & BACKLIGHT_MODULATION_FREQ_MASK) >>
  81. BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
  82. }
  83. /**
  84. * Sets the power state for the panel.
  85. */
  86. static void intel_lvds_set_power(struct drm_device *dev, bool on)
  87. {
  88. struct drm_i915_private *dev_priv = dev->dev_private;
  89. u32 ctl_reg, status_reg, lvds_reg;
  90. if (HAS_PCH_SPLIT(dev)) {
  91. ctl_reg = PCH_PP_CONTROL;
  92. status_reg = PCH_PP_STATUS;
  93. lvds_reg = PCH_LVDS;
  94. } else {
  95. ctl_reg = PP_CONTROL;
  96. status_reg = PP_STATUS;
  97. lvds_reg = LVDS;
  98. }
  99. if (on) {
  100. I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);
  101. POSTING_READ(lvds_reg);
  102. I915_WRITE(ctl_reg, I915_READ(ctl_reg) |
  103. POWER_TARGET_ON);
  104. if (wait_for(I915_READ(status_reg) & PP_ON, 1000, 0))
  105. DRM_ERROR("timed out waiting to enable LVDS pipe");
  106. intel_lvds_set_backlight(dev, dev_priv->backlight_duty_cycle);
  107. } else {
  108. intel_lvds_set_backlight(dev, 0);
  109. I915_WRITE(ctl_reg, I915_READ(ctl_reg) &
  110. ~POWER_TARGET_ON);
  111. if (wait_for((I915_READ(status_reg) & PP_ON) == 0, 1000, 0))
  112. DRM_ERROR("timed out waiting for LVDS pipe to turn off");
  113. I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN);
  114. POSTING_READ(lvds_reg);
  115. }
  116. }
  117. static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
  118. {
  119. struct drm_device *dev = encoder->dev;
  120. if (mode == DRM_MODE_DPMS_ON)
  121. intel_lvds_set_power(dev, true);
  122. else
  123. intel_lvds_set_power(dev, false);
  124. /* XXX: We never power down the LVDS pairs. */
  125. }
  126. static int intel_lvds_mode_valid(struct drm_connector *connector,
  127. struct drm_display_mode *mode)
  128. {
  129. struct drm_device *dev = connector->dev;
  130. struct drm_i915_private *dev_priv = dev->dev_private;
  131. struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
  132. if (fixed_mode) {
  133. if (mode->hdisplay > fixed_mode->hdisplay)
  134. return MODE_PANEL;
  135. if (mode->vdisplay > fixed_mode->vdisplay)
  136. return MODE_PANEL;
  137. }
  138. return MODE_OK;
  139. }
  140. static void
  141. centre_horizontally(struct drm_display_mode *mode,
  142. int width)
  143. {
  144. u32 border, sync_pos, blank_width, sync_width;
  145. /* keep the hsync and hblank widths constant */
  146. sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
  147. blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
  148. sync_pos = (blank_width - sync_width + 1) / 2;
  149. border = (mode->hdisplay - width + 1) / 2;
  150. border += border & 1; /* make the border even */
  151. mode->crtc_hdisplay = width;
  152. mode->crtc_hblank_start = width + border;
  153. mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
  154. mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
  155. mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
  156. }
  157. static void
  158. centre_vertically(struct drm_display_mode *mode,
  159. int height)
  160. {
  161. u32 border, sync_pos, blank_width, sync_width;
  162. /* keep the vsync and vblank widths constant */
  163. sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
  164. blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
  165. sync_pos = (blank_width - sync_width + 1) / 2;
  166. border = (mode->vdisplay - height + 1) / 2;
  167. mode->crtc_vdisplay = height;
  168. mode->crtc_vblank_start = height + border;
  169. mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
  170. mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
  171. mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
  172. }
  173. static inline u32 panel_fitter_scaling(u32 source, u32 target)
  174. {
  175. /*
  176. * Floating point operation is not supported. So the FACTOR
  177. * is defined, which can avoid the floating point computation
  178. * when calculating the panel ratio.
  179. */
  180. #define ACCURACY 12
  181. #define FACTOR (1 << ACCURACY)
  182. u32 ratio = source * FACTOR / target;
  183. return (FACTOR * ratio + FACTOR/2) / FACTOR;
  184. }
  185. static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
  186. struct drm_display_mode *mode,
  187. struct drm_display_mode *adjusted_mode)
  188. {
  189. struct drm_device *dev = encoder->dev;
  190. struct drm_i915_private *dev_priv = dev->dev_private;
  191. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  192. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  193. struct drm_encoder *tmp_encoder;
  194. u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
  195. /* Should never happen!! */
  196. if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
  197. DRM_ERROR("Can't support LVDS on pipe A\n");
  198. return false;
  199. }
  200. /* Should never happen!! */
  201. list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
  202. if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
  203. DRM_ERROR("Can't enable LVDS and another "
  204. "encoder on the same pipe\n");
  205. return false;
  206. }
  207. }
  208. /* If we don't have a panel mode, there is nothing we can do */
  209. if (dev_priv->panel_fixed_mode == NULL)
  210. return true;
  211. /*
  212. * We have timings from the BIOS for the panel, put them in
  213. * to the adjusted mode. The CRTC will be set up for this mode,
  214. * with the panel scaling set up to source from the H/VDisplay
  215. * of the original mode.
  216. */
  217. intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode);
  218. if (HAS_PCH_SPLIT(dev)) {
  219. intel_pch_panel_fitting(dev, intel_lvds->fitting_mode,
  220. mode, adjusted_mode);
  221. return true;
  222. }
  223. /* Make sure pre-965s set dither correctly */
  224. if (!IS_I965G(dev)) {
  225. if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
  226. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  227. }
  228. /* Native modes don't need fitting */
  229. if (adjusted_mode->hdisplay == mode->hdisplay &&
  230. adjusted_mode->vdisplay == mode->vdisplay)
  231. goto out;
  232. /* 965+ wants fuzzy fitting */
  233. if (IS_I965G(dev))
  234. pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
  235. PFIT_FILTER_FUZZY);
  236. /*
  237. * Enable automatic panel scaling for non-native modes so that they fill
  238. * the screen. Should be enabled before the pipe is enabled, according
  239. * to register description and PRM.
  240. * Change the value here to see the borders for debugging
  241. */
  242. I915_WRITE(BCLRPAT_A, 0);
  243. I915_WRITE(BCLRPAT_B, 0);
  244. switch (intel_lvds->fitting_mode) {
  245. case DRM_MODE_SCALE_CENTER:
  246. /*
  247. * For centered modes, we have to calculate border widths &
  248. * heights and modify the values programmed into the CRTC.
  249. */
  250. centre_horizontally(adjusted_mode, mode->hdisplay);
  251. centre_vertically(adjusted_mode, mode->vdisplay);
  252. border = LVDS_BORDER_ENABLE;
  253. break;
  254. case DRM_MODE_SCALE_ASPECT:
  255. /* Scale but preserve the aspect ratio */
  256. if (IS_I965G(dev)) {
  257. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  258. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  259. pfit_control |= PFIT_ENABLE;
  260. /* 965+ is easy, it does everything in hw */
  261. if (scaled_width > scaled_height)
  262. pfit_control |= PFIT_SCALING_PILLAR;
  263. else if (scaled_width < scaled_height)
  264. pfit_control |= PFIT_SCALING_LETTER;
  265. else
  266. pfit_control |= PFIT_SCALING_AUTO;
  267. } else {
  268. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  269. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  270. /*
  271. * For earlier chips we have to calculate the scaling
  272. * ratio by hand and program it into the
  273. * PFIT_PGM_RATIO register
  274. */
  275. if (scaled_width > scaled_height) { /* pillar */
  276. centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
  277. border = LVDS_BORDER_ENABLE;
  278. if (mode->vdisplay != adjusted_mode->vdisplay) {
  279. u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
  280. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  281. bits << PFIT_VERT_SCALE_SHIFT);
  282. pfit_control |= (PFIT_ENABLE |
  283. VERT_INTERP_BILINEAR |
  284. HORIZ_INTERP_BILINEAR);
  285. }
  286. } else if (scaled_width < scaled_height) { /* letter */
  287. centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
  288. border = LVDS_BORDER_ENABLE;
  289. if (mode->hdisplay != adjusted_mode->hdisplay) {
  290. u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
  291. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  292. bits << PFIT_VERT_SCALE_SHIFT);
  293. pfit_control |= (PFIT_ENABLE |
  294. VERT_INTERP_BILINEAR |
  295. HORIZ_INTERP_BILINEAR);
  296. }
  297. } else
  298. /* Aspects match, Let hw scale both directions */
  299. pfit_control |= (PFIT_ENABLE |
  300. VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  301. VERT_INTERP_BILINEAR |
  302. HORIZ_INTERP_BILINEAR);
  303. }
  304. break;
  305. case DRM_MODE_SCALE_FULLSCREEN:
  306. /*
  307. * Full scaling, even if it changes the aspect ratio.
  308. * Fortunately this is all done for us in hw.
  309. */
  310. pfit_control |= PFIT_ENABLE;
  311. if (IS_I965G(dev))
  312. pfit_control |= PFIT_SCALING_AUTO;
  313. else
  314. pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  315. VERT_INTERP_BILINEAR |
  316. HORIZ_INTERP_BILINEAR);
  317. break;
  318. default:
  319. break;
  320. }
  321. out:
  322. intel_lvds->pfit_control = pfit_control;
  323. intel_lvds->pfit_pgm_ratios = pfit_pgm_ratios;
  324. dev_priv->lvds_border_bits = border;
  325. /*
  326. * XXX: It would be nice to support lower refresh rates on the
  327. * panels to reduce power consumption, and perhaps match the
  328. * user's requested refresh rate.
  329. */
  330. return true;
  331. }
  332. static void intel_lvds_prepare(struct drm_encoder *encoder)
  333. {
  334. struct drm_device *dev = encoder->dev;
  335. struct drm_i915_private *dev_priv = dev->dev_private;
  336. u32 reg;
  337. if (HAS_PCH_SPLIT(dev))
  338. reg = BLC_PWM_CPU_CTL;
  339. else
  340. reg = BLC_PWM_CTL;
  341. dev_priv->saveBLC_PWM_CTL = I915_READ(reg);
  342. dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
  343. BACKLIGHT_DUTY_CYCLE_MASK);
  344. intel_lvds_set_power(dev, false);
  345. }
  346. static void intel_lvds_commit( struct drm_encoder *encoder)
  347. {
  348. struct drm_device *dev = encoder->dev;
  349. struct drm_i915_private *dev_priv = dev->dev_private;
  350. if (dev_priv->backlight_duty_cycle == 0)
  351. dev_priv->backlight_duty_cycle =
  352. intel_lvds_get_max_backlight(dev);
  353. intel_lvds_set_power(dev, true);
  354. }
  355. static void intel_lvds_mode_set(struct drm_encoder *encoder,
  356. struct drm_display_mode *mode,
  357. struct drm_display_mode *adjusted_mode)
  358. {
  359. struct drm_device *dev = encoder->dev;
  360. struct drm_i915_private *dev_priv = dev->dev_private;
  361. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  362. /*
  363. * The LVDS pin pair will already have been turned on in the
  364. * intel_crtc_mode_set since it has a large impact on the DPLL
  365. * settings.
  366. */
  367. if (HAS_PCH_SPLIT(dev))
  368. return;
  369. /*
  370. * Enable automatic panel scaling so that non-native modes fill the
  371. * screen. Should be enabled before the pipe is enabled, according to
  372. * register description and PRM.
  373. */
  374. I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios);
  375. I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control);
  376. }
  377. /**
  378. * Detect the LVDS connection.
  379. *
  380. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  381. * connected and closed means disconnected. We also send hotplug events as
  382. * needed, using lid status notification from the input layer.
  383. */
  384. static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector)
  385. {
  386. struct drm_device *dev = connector->dev;
  387. enum drm_connector_status status = connector_status_connected;
  388. /* ACPI lid methods were generally unreliable in this generation, so
  389. * don't even bother.
  390. */
  391. if (IS_GEN2(dev) || IS_GEN3(dev))
  392. return connector_status_connected;
  393. return status;
  394. }
  395. /**
  396. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  397. */
  398. static int intel_lvds_get_modes(struct drm_connector *connector)
  399. {
  400. struct drm_device *dev = connector->dev;
  401. struct drm_encoder *encoder = intel_attached_encoder(connector);
  402. struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
  403. struct drm_i915_private *dev_priv = dev->dev_private;
  404. int ret = 0;
  405. if (dev_priv->lvds_edid_good) {
  406. ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
  407. if (ret)
  408. return ret;
  409. }
  410. /* Didn't get an EDID, so
  411. * Set wide sync ranges so we get all modes
  412. * handed to valid_mode for checking
  413. */
  414. connector->display_info.min_vfreq = 0;
  415. connector->display_info.max_vfreq = 200;
  416. connector->display_info.min_hfreq = 0;
  417. connector->display_info.max_hfreq = 200;
  418. if (dev_priv->panel_fixed_mode != NULL) {
  419. struct drm_display_mode *mode;
  420. mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
  421. drm_mode_probed_add(connector, mode);
  422. return 1;
  423. }
  424. return 0;
  425. }
  426. static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
  427. {
  428. DRM_DEBUG_KMS("Skipping forced modeset for %s\n", id->ident);
  429. return 1;
  430. }
  431. /* The GPU hangs up on these systems if modeset is performed on LID open */
  432. static const struct dmi_system_id intel_no_modeset_on_lid[] = {
  433. {
  434. .callback = intel_no_modeset_on_lid_dmi_callback,
  435. .ident = "Toshiba Tecra A11",
  436. .matches = {
  437. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  438. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
  439. },
  440. },
  441. { } /* terminating entry */
  442. };
  443. /*
  444. * Lid events. Note the use of 'modeset_on_lid':
  445. * - we set it on lid close, and reset it on open
  446. * - we use it as a "only once" bit (ie we ignore
  447. * duplicate events where it was already properly
  448. * set/reset)
  449. * - the suspend/resume paths will also set it to
  450. * zero, since they restore the mode ("lid open").
  451. */
  452. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  453. void *unused)
  454. {
  455. struct drm_i915_private *dev_priv =
  456. container_of(nb, struct drm_i915_private, lid_notifier);
  457. struct drm_device *dev = dev_priv->dev;
  458. struct drm_connector *connector = dev_priv->int_lvds_connector;
  459. /*
  460. * check and update the status of LVDS connector after receiving
  461. * the LID nofication event.
  462. */
  463. if (connector)
  464. connector->status = connector->funcs->detect(connector);
  465. /* Don't force modeset on machines where it causes a GPU lockup */
  466. if (dmi_check_system(intel_no_modeset_on_lid))
  467. return NOTIFY_OK;
  468. if (!acpi_lid_open()) {
  469. dev_priv->modeset_on_lid = 1;
  470. return NOTIFY_OK;
  471. }
  472. if (!dev_priv->modeset_on_lid)
  473. return NOTIFY_OK;
  474. dev_priv->modeset_on_lid = 0;
  475. mutex_lock(&dev->mode_config.mutex);
  476. drm_helper_resume_force_mode(dev);
  477. mutex_unlock(&dev->mode_config.mutex);
  478. return NOTIFY_OK;
  479. }
  480. /**
  481. * intel_lvds_destroy - unregister and free LVDS structures
  482. * @connector: connector to free
  483. *
  484. * Unregister the DDC bus for this connector then free the driver private
  485. * structure.
  486. */
  487. static void intel_lvds_destroy(struct drm_connector *connector)
  488. {
  489. struct drm_device *dev = connector->dev;
  490. struct drm_i915_private *dev_priv = dev->dev_private;
  491. if (dev_priv->lid_notifier.notifier_call)
  492. acpi_lid_notifier_unregister(&dev_priv->lid_notifier);
  493. drm_sysfs_connector_remove(connector);
  494. drm_connector_cleanup(connector);
  495. kfree(connector);
  496. }
  497. static int intel_lvds_set_property(struct drm_connector *connector,
  498. struct drm_property *property,
  499. uint64_t value)
  500. {
  501. struct drm_device *dev = connector->dev;
  502. if (property == dev->mode_config.scaling_mode_property &&
  503. connector->encoder) {
  504. struct drm_crtc *crtc = connector->encoder->crtc;
  505. struct drm_encoder *encoder = connector->encoder;
  506. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  507. if (value == DRM_MODE_SCALE_NONE) {
  508. DRM_DEBUG_KMS("no scaling not supported\n");
  509. return 0;
  510. }
  511. if (intel_lvds->fitting_mode == value) {
  512. /* the LVDS scaling property is not changed */
  513. return 0;
  514. }
  515. intel_lvds->fitting_mode = value;
  516. if (crtc && crtc->enabled) {
  517. /*
  518. * If the CRTC is enabled, the display will be changed
  519. * according to the new panel fitting mode.
  520. */
  521. drm_crtc_helper_set_mode(crtc, &crtc->mode,
  522. crtc->x, crtc->y, crtc->fb);
  523. }
  524. }
  525. return 0;
  526. }
  527. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  528. .dpms = intel_lvds_dpms,
  529. .mode_fixup = intel_lvds_mode_fixup,
  530. .prepare = intel_lvds_prepare,
  531. .mode_set = intel_lvds_mode_set,
  532. .commit = intel_lvds_commit,
  533. };
  534. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  535. .get_modes = intel_lvds_get_modes,
  536. .mode_valid = intel_lvds_mode_valid,
  537. .best_encoder = intel_attached_encoder,
  538. };
  539. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  540. .dpms = drm_helper_connector_dpms,
  541. .detect = intel_lvds_detect,
  542. .fill_modes = drm_helper_probe_single_connector_modes,
  543. .set_property = intel_lvds_set_property,
  544. .destroy = intel_lvds_destroy,
  545. };
  546. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  547. .destroy = intel_encoder_destroy,
  548. };
  549. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  550. {
  551. DRM_DEBUG_KMS("Skipping LVDS initialization for %s\n", id->ident);
  552. return 1;
  553. }
  554. /* These systems claim to have LVDS, but really don't */
  555. static const struct dmi_system_id intel_no_lvds[] = {
  556. {
  557. .callback = intel_no_lvds_dmi_callback,
  558. .ident = "Apple Mac Mini (Core series)",
  559. .matches = {
  560. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  561. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  562. },
  563. },
  564. {
  565. .callback = intel_no_lvds_dmi_callback,
  566. .ident = "Apple Mac Mini (Core 2 series)",
  567. .matches = {
  568. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  569. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  570. },
  571. },
  572. {
  573. .callback = intel_no_lvds_dmi_callback,
  574. .ident = "MSI IM-945GSE-A",
  575. .matches = {
  576. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  577. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  578. },
  579. },
  580. {
  581. .callback = intel_no_lvds_dmi_callback,
  582. .ident = "Dell Studio Hybrid",
  583. .matches = {
  584. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  585. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  586. },
  587. },
  588. {
  589. .callback = intel_no_lvds_dmi_callback,
  590. .ident = "AOpen Mini PC",
  591. .matches = {
  592. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  593. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  594. },
  595. },
  596. {
  597. .callback = intel_no_lvds_dmi_callback,
  598. .ident = "AOpen Mini PC MP915",
  599. .matches = {
  600. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  601. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  602. },
  603. },
  604. {
  605. .callback = intel_no_lvds_dmi_callback,
  606. .ident = "Aopen i945GTt-VFA",
  607. .matches = {
  608. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  609. },
  610. },
  611. {
  612. .callback = intel_no_lvds_dmi_callback,
  613. .ident = "Clientron U800",
  614. .matches = {
  615. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  616. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  617. },
  618. },
  619. { } /* terminating entry */
  620. };
  621. /**
  622. * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
  623. * @dev: drm device
  624. * @connector: LVDS connector
  625. *
  626. * Find the reduced downclock for LVDS in EDID.
  627. */
  628. static void intel_find_lvds_downclock(struct drm_device *dev,
  629. struct drm_connector *connector)
  630. {
  631. struct drm_i915_private *dev_priv = dev->dev_private;
  632. struct drm_display_mode *scan, *panel_fixed_mode;
  633. int temp_downclock;
  634. panel_fixed_mode = dev_priv->panel_fixed_mode;
  635. temp_downclock = panel_fixed_mode->clock;
  636. mutex_lock(&dev->mode_config.mutex);
  637. list_for_each_entry(scan, &connector->probed_modes, head) {
  638. /*
  639. * If one mode has the same resolution with the fixed_panel
  640. * mode while they have the different refresh rate, it means
  641. * that the reduced downclock is found for the LVDS. In such
  642. * case we can set the different FPx0/1 to dynamically select
  643. * between low and high frequency.
  644. */
  645. if (scan->hdisplay == panel_fixed_mode->hdisplay &&
  646. scan->hsync_start == panel_fixed_mode->hsync_start &&
  647. scan->hsync_end == panel_fixed_mode->hsync_end &&
  648. scan->htotal == panel_fixed_mode->htotal &&
  649. scan->vdisplay == panel_fixed_mode->vdisplay &&
  650. scan->vsync_start == panel_fixed_mode->vsync_start &&
  651. scan->vsync_end == panel_fixed_mode->vsync_end &&
  652. scan->vtotal == panel_fixed_mode->vtotal) {
  653. if (scan->clock < temp_downclock) {
  654. /*
  655. * The downclock is already found. But we
  656. * expect to find the lower downclock.
  657. */
  658. temp_downclock = scan->clock;
  659. }
  660. }
  661. }
  662. mutex_unlock(&dev->mode_config.mutex);
  663. if (temp_downclock < panel_fixed_mode->clock &&
  664. i915_lvds_downclock) {
  665. /* We found the downclock for LVDS. */
  666. dev_priv->lvds_downclock_avail = 1;
  667. dev_priv->lvds_downclock = temp_downclock;
  668. DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
  669. "Normal clock %dKhz, downclock %dKhz\n",
  670. panel_fixed_mode->clock, temp_downclock);
  671. }
  672. return;
  673. }
  674. /*
  675. * Enumerate the child dev array parsed from VBT to check whether
  676. * the LVDS is present.
  677. * If it is present, return 1.
  678. * If it is not present, return false.
  679. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  680. * Note: The addin_offset should also be checked for LVDS panel.
  681. * Only when it is non-zero, it is assumed that it is present.
  682. */
  683. static int lvds_is_present_in_vbt(struct drm_device *dev)
  684. {
  685. struct drm_i915_private *dev_priv = dev->dev_private;
  686. struct child_device_config *p_child;
  687. int i, ret;
  688. if (!dev_priv->child_dev_num)
  689. return 1;
  690. ret = 0;
  691. for (i = 0; i < dev_priv->child_dev_num; i++) {
  692. p_child = dev_priv->child_dev + i;
  693. /*
  694. * If the device type is not LFP, continue.
  695. * If the device type is 0x22, it is also regarded as LFP.
  696. */
  697. if (p_child->device_type != DEVICE_TYPE_INT_LFP &&
  698. p_child->device_type != DEVICE_TYPE_LFP)
  699. continue;
  700. /* The addin_offset should be checked. Only when it is
  701. * non-zero, it is regarded as present.
  702. */
  703. if (p_child->addin_offset) {
  704. ret = 1;
  705. break;
  706. }
  707. }
  708. return ret;
  709. }
  710. /**
  711. * intel_lvds_init - setup LVDS connectors on this device
  712. * @dev: drm device
  713. *
  714. * Create the connector, register the LVDS DDC bus, and try to figure out what
  715. * modes we can display on the LVDS panel (if present).
  716. */
  717. void intel_lvds_init(struct drm_device *dev)
  718. {
  719. struct drm_i915_private *dev_priv = dev->dev_private;
  720. struct intel_lvds *intel_lvds;
  721. struct intel_encoder *intel_encoder;
  722. struct intel_connector *intel_connector;
  723. struct drm_connector *connector;
  724. struct drm_encoder *encoder;
  725. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  726. struct drm_crtc *crtc;
  727. u32 lvds;
  728. int pipe, gpio = GPIOC;
  729. /* Skip init on machines we know falsely report LVDS */
  730. if (dmi_check_system(intel_no_lvds))
  731. return;
  732. if (!lvds_is_present_in_vbt(dev)) {
  733. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  734. return;
  735. }
  736. if (HAS_PCH_SPLIT(dev)) {
  737. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  738. return;
  739. if (dev_priv->edp_support) {
  740. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  741. return;
  742. }
  743. gpio = PCH_GPIOC;
  744. }
  745. intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL);
  746. if (!intel_lvds) {
  747. return;
  748. }
  749. intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
  750. if (!intel_connector) {
  751. kfree(intel_lvds);
  752. return;
  753. }
  754. intel_encoder = &intel_lvds->base;
  755. encoder = &intel_encoder->enc;
  756. connector = &intel_connector->base;
  757. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  758. DRM_MODE_CONNECTOR_LVDS);
  759. drm_encoder_init(dev, &intel_encoder->enc, &intel_lvds_enc_funcs,
  760. DRM_MODE_ENCODER_LVDS);
  761. drm_mode_connector_attach_encoder(&intel_connector->base, &intel_encoder->enc);
  762. intel_encoder->type = INTEL_OUTPUT_LVDS;
  763. intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT);
  764. intel_encoder->crtc_mask = (1 << 1);
  765. if (IS_I965G(dev))
  766. intel_encoder->crtc_mask |= (1 << 0);
  767. drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
  768. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  769. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  770. connector->interlace_allowed = false;
  771. connector->doublescan_allowed = false;
  772. /* create the scaling mode property */
  773. drm_mode_create_scaling_mode_property(dev);
  774. /*
  775. * the initial panel fitting mode will be FULL_SCREEN.
  776. */
  777. drm_connector_attach_property(&intel_connector->base,
  778. dev->mode_config.scaling_mode_property,
  779. DRM_MODE_SCALE_ASPECT);
  780. intel_lvds->fitting_mode = DRM_MODE_SCALE_ASPECT;
  781. /*
  782. * LVDS discovery:
  783. * 1) check for EDID on DDC
  784. * 2) check for VBT data
  785. * 3) check to see if LVDS is already on
  786. * if none of the above, no panel
  787. * 4) make sure lid is open
  788. * if closed, act like it's not there for now
  789. */
  790. /* Set up the DDC bus. */
  791. intel_encoder->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C");
  792. if (!intel_encoder->ddc_bus) {
  793. dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
  794. "failed.\n");
  795. goto failed;
  796. }
  797. /*
  798. * Attempt to get the fixed panel mode from DDC. Assume that the
  799. * preferred mode is the right one.
  800. */
  801. dev_priv->lvds_edid_good = true;
  802. if (!intel_ddc_get_modes(connector, intel_encoder->ddc_bus))
  803. dev_priv->lvds_edid_good = false;
  804. list_for_each_entry(scan, &connector->probed_modes, head) {
  805. mutex_lock(&dev->mode_config.mutex);
  806. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  807. dev_priv->panel_fixed_mode =
  808. drm_mode_duplicate(dev, scan);
  809. mutex_unlock(&dev->mode_config.mutex);
  810. intel_find_lvds_downclock(dev, connector);
  811. goto out;
  812. }
  813. mutex_unlock(&dev->mode_config.mutex);
  814. }
  815. /* Failed to get EDID, what about VBT? */
  816. if (dev_priv->lfp_lvds_vbt_mode) {
  817. mutex_lock(&dev->mode_config.mutex);
  818. dev_priv->panel_fixed_mode =
  819. drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  820. mutex_unlock(&dev->mode_config.mutex);
  821. if (dev_priv->panel_fixed_mode) {
  822. dev_priv->panel_fixed_mode->type |=
  823. DRM_MODE_TYPE_PREFERRED;
  824. goto out;
  825. }
  826. }
  827. /*
  828. * If we didn't get EDID, try checking if the panel is already turned
  829. * on. If so, assume that whatever is currently programmed is the
  830. * correct mode.
  831. */
  832. /* Ironlake: FIXME if still fail, not try pipe mode now */
  833. if (HAS_PCH_SPLIT(dev))
  834. goto failed;
  835. lvds = I915_READ(LVDS);
  836. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  837. crtc = intel_get_crtc_from_pipe(dev, pipe);
  838. if (crtc && (lvds & LVDS_PORT_EN)) {
  839. dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc);
  840. if (dev_priv->panel_fixed_mode) {
  841. dev_priv->panel_fixed_mode->type |=
  842. DRM_MODE_TYPE_PREFERRED;
  843. goto out;
  844. }
  845. }
  846. /* If we still don't have a mode after all that, give up. */
  847. if (!dev_priv->panel_fixed_mode)
  848. goto failed;
  849. out:
  850. if (HAS_PCH_SPLIT(dev)) {
  851. u32 pwm;
  852. /* make sure PWM is enabled */
  853. pwm = I915_READ(BLC_PWM_CPU_CTL2);
  854. pwm |= (PWM_ENABLE | PWM_PIPE_B);
  855. I915_WRITE(BLC_PWM_CPU_CTL2, pwm);
  856. pwm = I915_READ(BLC_PWM_PCH_CTL1);
  857. pwm |= PWM_PCH_ENABLE;
  858. I915_WRITE(BLC_PWM_PCH_CTL1, pwm);
  859. }
  860. dev_priv->lid_notifier.notifier_call = intel_lid_notify;
  861. if (acpi_lid_notifier_register(&dev_priv->lid_notifier)) {
  862. DRM_DEBUG_KMS("lid notifier registration failed\n");
  863. dev_priv->lid_notifier.notifier_call = NULL;
  864. }
  865. /* keep the LVDS connector */
  866. dev_priv->int_lvds_connector = connector;
  867. drm_sysfs_connector_add(connector);
  868. return;
  869. failed:
  870. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  871. if (intel_encoder->ddc_bus)
  872. intel_i2c_destroy(intel_encoder->ddc_bus);
  873. drm_connector_cleanup(connector);
  874. drm_encoder_cleanup(encoder);
  875. kfree(intel_lvds);
  876. kfree(intel_connector);
  877. }