intel_lvds.c 31 KB

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