intel_lvds.c 29 KB

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