intel_lvds.c 32 KB

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