intel_lvds.c 31 KB

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