intel_lvds.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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. bool is_dual_link;
  48. u32 reg;
  49. struct intel_lvds_connector *attached_connector;
  50. };
  51. static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
  52. {
  53. return container_of(encoder, struct intel_lvds_encoder, base.base);
  54. }
  55. static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
  56. {
  57. return container_of(connector, struct intel_lvds_connector, base.base);
  58. }
  59. static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
  60. enum pipe *pipe)
  61. {
  62. struct drm_device *dev = encoder->base.dev;
  63. struct drm_i915_private *dev_priv = dev->dev_private;
  64. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  65. u32 tmp;
  66. tmp = I915_READ(lvds_encoder->reg);
  67. if (!(tmp & LVDS_PORT_EN))
  68. return false;
  69. if (HAS_PCH_CPT(dev))
  70. *pipe = PORT_TO_PIPE_CPT(tmp);
  71. else
  72. *pipe = PORT_TO_PIPE(tmp);
  73. return true;
  74. }
  75. static void intel_lvds_get_config(struct intel_encoder *encoder,
  76. struct intel_crtc_config *pipe_config)
  77. {
  78. struct drm_device *dev = encoder->base.dev;
  79. struct drm_i915_private *dev_priv = dev->dev_private;
  80. u32 lvds_reg, tmp, flags = 0;
  81. if (HAS_PCH_SPLIT(dev))
  82. lvds_reg = PCH_LVDS;
  83. else
  84. lvds_reg = LVDS;
  85. tmp = I915_READ(lvds_reg);
  86. if (tmp & LVDS_HSYNC_POLARITY)
  87. flags |= DRM_MODE_FLAG_NHSYNC;
  88. else
  89. flags |= DRM_MODE_FLAG_PHSYNC;
  90. if (tmp & LVDS_VSYNC_POLARITY)
  91. flags |= DRM_MODE_FLAG_NVSYNC;
  92. else
  93. flags |= DRM_MODE_FLAG_PVSYNC;
  94. pipe_config->adjusted_mode.flags |= flags;
  95. /* gen2/3 store dither state in pfit control, needs to match */
  96. if (INTEL_INFO(dev)->gen < 4) {
  97. tmp = I915_READ(PFIT_CONTROL);
  98. pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
  99. }
  100. }
  101. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  102. * This is an exception to the general rule that mode_set doesn't turn
  103. * things on.
  104. */
  105. static void intel_pre_pll_enable_lvds(struct intel_encoder *encoder)
  106. {
  107. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  108. struct drm_device *dev = encoder->base.dev;
  109. struct drm_i915_private *dev_priv = dev->dev_private;
  110. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  111. struct drm_display_mode *fixed_mode =
  112. lvds_encoder->attached_connector->base.panel.fixed_mode;
  113. int pipe = intel_crtc->pipe;
  114. u32 temp;
  115. temp = I915_READ(lvds_encoder->reg);
  116. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  117. if (HAS_PCH_CPT(dev)) {
  118. temp &= ~PORT_TRANS_SEL_MASK;
  119. temp |= PORT_TRANS_SEL_CPT(pipe);
  120. } else {
  121. if (pipe == 1) {
  122. temp |= LVDS_PIPEB_SELECT;
  123. } else {
  124. temp &= ~LVDS_PIPEB_SELECT;
  125. }
  126. }
  127. /* set the corresponsding LVDS_BORDER bit */
  128. temp &= ~LVDS_BORDER_ENABLE;
  129. temp |= intel_crtc->config.gmch_pfit.lvds_border_bits;
  130. /* Set the B0-B3 data pairs corresponding to whether we're going to
  131. * set the DPLLs for dual-channel mode or not.
  132. */
  133. if (lvds_encoder->is_dual_link)
  134. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  135. else
  136. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  137. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  138. * appropriately here, but we need to look more thoroughly into how
  139. * panels behave in the two modes.
  140. */
  141. /* Set the dithering flag on LVDS as needed, note that there is no
  142. * special lvds dither control bit on pch-split platforms, dithering is
  143. * only controlled through the PIPECONF reg. */
  144. if (INTEL_INFO(dev)->gen == 4) {
  145. /* Bspec wording suggests that LVDS port dithering only exists
  146. * for 18bpp panels. */
  147. if (intel_crtc->config.dither &&
  148. intel_crtc->config.pipe_bpp == 18)
  149. temp |= LVDS_ENABLE_DITHER;
  150. else
  151. temp &= ~LVDS_ENABLE_DITHER;
  152. }
  153. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  154. if (fixed_mode->flags & DRM_MODE_FLAG_NHSYNC)
  155. temp |= LVDS_HSYNC_POLARITY;
  156. if (fixed_mode->flags & DRM_MODE_FLAG_NVSYNC)
  157. temp |= LVDS_VSYNC_POLARITY;
  158. I915_WRITE(lvds_encoder->reg, temp);
  159. }
  160. /**
  161. * Sets the power state for the panel.
  162. */
  163. static void intel_enable_lvds(struct intel_encoder *encoder)
  164. {
  165. struct drm_device *dev = encoder->base.dev;
  166. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  167. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  168. struct drm_i915_private *dev_priv = dev->dev_private;
  169. u32 ctl_reg, stat_reg;
  170. if (HAS_PCH_SPLIT(dev)) {
  171. ctl_reg = PCH_PP_CONTROL;
  172. stat_reg = PCH_PP_STATUS;
  173. } else {
  174. ctl_reg = PP_CONTROL;
  175. stat_reg = PP_STATUS;
  176. }
  177. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
  178. I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
  179. POSTING_READ(lvds_encoder->reg);
  180. if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
  181. DRM_ERROR("timed out waiting for panel to power on\n");
  182. intel_panel_enable_backlight(dev, intel_crtc->pipe);
  183. }
  184. static void intel_disable_lvds(struct intel_encoder *encoder)
  185. {
  186. struct drm_device *dev = encoder->base.dev;
  187. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  188. struct drm_i915_private *dev_priv = dev->dev_private;
  189. u32 ctl_reg, stat_reg;
  190. if (HAS_PCH_SPLIT(dev)) {
  191. ctl_reg = PCH_PP_CONTROL;
  192. stat_reg = PCH_PP_STATUS;
  193. } else {
  194. ctl_reg = PP_CONTROL;
  195. stat_reg = PP_STATUS;
  196. }
  197. intel_panel_disable_backlight(dev);
  198. I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
  199. if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
  200. DRM_ERROR("timed out waiting for panel to power off\n");
  201. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
  202. POSTING_READ(lvds_encoder->reg);
  203. }
  204. static int intel_lvds_mode_valid(struct drm_connector *connector,
  205. struct drm_display_mode *mode)
  206. {
  207. struct intel_connector *intel_connector = to_intel_connector(connector);
  208. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  209. if (mode->hdisplay > fixed_mode->hdisplay)
  210. return MODE_PANEL;
  211. if (mode->vdisplay > fixed_mode->vdisplay)
  212. return MODE_PANEL;
  213. return MODE_OK;
  214. }
  215. static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
  216. struct intel_crtc_config *pipe_config)
  217. {
  218. struct drm_device *dev = intel_encoder->base.dev;
  219. struct drm_i915_private *dev_priv = dev->dev_private;
  220. struct intel_lvds_encoder *lvds_encoder =
  221. to_lvds_encoder(&intel_encoder->base);
  222. struct intel_connector *intel_connector =
  223. &lvds_encoder->attached_connector->base;
  224. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  225. struct intel_crtc *intel_crtc = lvds_encoder->base.new_crtc;
  226. unsigned int lvds_bpp;
  227. /* Should never happen!! */
  228. if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
  229. DRM_ERROR("Can't support LVDS on pipe A\n");
  230. return false;
  231. }
  232. if ((I915_READ(lvds_encoder->reg) & LVDS_A3_POWER_MASK) ==
  233. LVDS_A3_POWER_UP)
  234. lvds_bpp = 8*3;
  235. else
  236. lvds_bpp = 6*3;
  237. if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
  238. DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
  239. pipe_config->pipe_bpp, lvds_bpp);
  240. pipe_config->pipe_bpp = lvds_bpp;
  241. }
  242. /*
  243. * We have timings from the BIOS for the panel, put them in
  244. * to the adjusted mode. The CRTC will be set up for this mode,
  245. * with the panel scaling set up to source from the H/VDisplay
  246. * of the original mode.
  247. */
  248. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  249. adjusted_mode);
  250. if (HAS_PCH_SPLIT(dev)) {
  251. pipe_config->has_pch_encoder = true;
  252. intel_pch_panel_fitting(intel_crtc, pipe_config,
  253. intel_connector->panel.fitting_mode);
  254. } else {
  255. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  256. intel_connector->panel.fitting_mode);
  257. }
  258. /*
  259. * XXX: It would be nice to support lower refresh rates on the
  260. * panels to reduce power consumption, and perhaps match the
  261. * user's requested refresh rate.
  262. */
  263. return true;
  264. }
  265. static void intel_lvds_mode_set(struct drm_encoder *encoder,
  266. struct drm_display_mode *mode,
  267. struct drm_display_mode *adjusted_mode)
  268. {
  269. /*
  270. * The LVDS pin pair will already have been turned on in the
  271. * intel_crtc_mode_set since it has a large impact on the DPLL
  272. * settings.
  273. */
  274. }
  275. /**
  276. * Detect the LVDS connection.
  277. *
  278. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  279. * connected and closed means disconnected. We also send hotplug events as
  280. * needed, using lid status notification from the input layer.
  281. */
  282. static enum drm_connector_status
  283. intel_lvds_detect(struct drm_connector *connector, bool force)
  284. {
  285. struct drm_device *dev = connector->dev;
  286. enum drm_connector_status status;
  287. status = intel_panel_detect(dev);
  288. if (status != connector_status_unknown)
  289. return status;
  290. return connector_status_connected;
  291. }
  292. /**
  293. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  294. */
  295. static int intel_lvds_get_modes(struct drm_connector *connector)
  296. {
  297. struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
  298. struct drm_device *dev = connector->dev;
  299. struct drm_display_mode *mode;
  300. /* use cached edid if we have one */
  301. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  302. return drm_add_edid_modes(connector, lvds_connector->base.edid);
  303. mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
  304. if (mode == NULL)
  305. return 0;
  306. drm_mode_probed_add(connector, mode);
  307. return 1;
  308. }
  309. static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
  310. {
  311. DRM_INFO("Skipping forced modeset for %s\n", id->ident);
  312. return 1;
  313. }
  314. /* The GPU hangs up on these systems if modeset is performed on LID open */
  315. static const struct dmi_system_id intel_no_modeset_on_lid[] = {
  316. {
  317. .callback = intel_no_modeset_on_lid_dmi_callback,
  318. .ident = "Toshiba Tecra A11",
  319. .matches = {
  320. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  321. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
  322. },
  323. },
  324. { } /* terminating entry */
  325. };
  326. /*
  327. * Lid events. Note the use of 'modeset':
  328. * - we set it to MODESET_ON_LID_OPEN on lid close,
  329. * and set it to MODESET_DONE on open
  330. * - we use it as a "only once" bit (ie we ignore
  331. * duplicate events where it was already properly set)
  332. * - the suspend/resume paths will set it to
  333. * MODESET_SUSPENDED and ignore the lid open event,
  334. * because they restore the mode ("lid open").
  335. */
  336. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  337. void *unused)
  338. {
  339. struct intel_lvds_connector *lvds_connector =
  340. container_of(nb, struct intel_lvds_connector, lid_notifier);
  341. struct drm_connector *connector = &lvds_connector->base.base;
  342. struct drm_device *dev = connector->dev;
  343. struct drm_i915_private *dev_priv = dev->dev_private;
  344. if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
  345. return NOTIFY_OK;
  346. mutex_lock(&dev_priv->modeset_restore_lock);
  347. if (dev_priv->modeset_restore == MODESET_SUSPENDED)
  348. goto exit;
  349. /*
  350. * check and update the status of LVDS connector after receiving
  351. * the LID nofication event.
  352. */
  353. connector->status = connector->funcs->detect(connector, false);
  354. /* Don't force modeset on machines where it causes a GPU lockup */
  355. if (dmi_check_system(intel_no_modeset_on_lid))
  356. goto exit;
  357. if (!acpi_lid_open()) {
  358. /* do modeset on next lid open event */
  359. dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
  360. goto exit;
  361. }
  362. if (dev_priv->modeset_restore == MODESET_DONE)
  363. goto exit;
  364. drm_modeset_lock_all(dev);
  365. intel_modeset_setup_hw_state(dev, true);
  366. drm_modeset_unlock_all(dev);
  367. dev_priv->modeset_restore = MODESET_DONE;
  368. exit:
  369. mutex_unlock(&dev_priv->modeset_restore_lock);
  370. return NOTIFY_OK;
  371. }
  372. /**
  373. * intel_lvds_destroy - unregister and free LVDS structures
  374. * @connector: connector to free
  375. *
  376. * Unregister the DDC bus for this connector then free the driver private
  377. * structure.
  378. */
  379. static void intel_lvds_destroy(struct drm_connector *connector)
  380. {
  381. struct intel_lvds_connector *lvds_connector =
  382. to_lvds_connector(connector);
  383. if (lvds_connector->lid_notifier.notifier_call)
  384. acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
  385. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  386. kfree(lvds_connector->base.edid);
  387. intel_panel_fini(&lvds_connector->base.panel);
  388. drm_sysfs_connector_remove(connector);
  389. drm_connector_cleanup(connector);
  390. kfree(connector);
  391. }
  392. static int intel_lvds_set_property(struct drm_connector *connector,
  393. struct drm_property *property,
  394. uint64_t value)
  395. {
  396. struct intel_connector *intel_connector = to_intel_connector(connector);
  397. struct drm_device *dev = connector->dev;
  398. if (property == dev->mode_config.scaling_mode_property) {
  399. struct drm_crtc *crtc;
  400. if (value == DRM_MODE_SCALE_NONE) {
  401. DRM_DEBUG_KMS("no scaling not supported\n");
  402. return -EINVAL;
  403. }
  404. if (intel_connector->panel.fitting_mode == value) {
  405. /* the LVDS scaling property is not changed */
  406. return 0;
  407. }
  408. intel_connector->panel.fitting_mode = value;
  409. crtc = intel_attached_encoder(connector)->base.crtc;
  410. if (crtc && crtc->enabled) {
  411. /*
  412. * If the CRTC is enabled, the display will be changed
  413. * according to the new panel fitting mode.
  414. */
  415. intel_crtc_restore_mode(crtc);
  416. }
  417. }
  418. return 0;
  419. }
  420. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  421. .mode_set = intel_lvds_mode_set,
  422. };
  423. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  424. .get_modes = intel_lvds_get_modes,
  425. .mode_valid = intel_lvds_mode_valid,
  426. .best_encoder = intel_best_encoder,
  427. };
  428. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  429. .dpms = intel_connector_dpms,
  430. .detect = intel_lvds_detect,
  431. .fill_modes = drm_helper_probe_single_connector_modes,
  432. .set_property = intel_lvds_set_property,
  433. .destroy = intel_lvds_destroy,
  434. };
  435. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  436. .destroy = intel_encoder_destroy,
  437. };
  438. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  439. {
  440. DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
  441. return 1;
  442. }
  443. /* These systems claim to have LVDS, but really don't */
  444. static const struct dmi_system_id intel_no_lvds[] = {
  445. {
  446. .callback = intel_no_lvds_dmi_callback,
  447. .ident = "Apple Mac Mini (Core series)",
  448. .matches = {
  449. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  450. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  451. },
  452. },
  453. {
  454. .callback = intel_no_lvds_dmi_callback,
  455. .ident = "Apple Mac Mini (Core 2 series)",
  456. .matches = {
  457. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  458. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  459. },
  460. },
  461. {
  462. .callback = intel_no_lvds_dmi_callback,
  463. .ident = "MSI IM-945GSE-A",
  464. .matches = {
  465. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  466. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  467. },
  468. },
  469. {
  470. .callback = intel_no_lvds_dmi_callback,
  471. .ident = "Dell Studio Hybrid",
  472. .matches = {
  473. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  474. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  475. },
  476. },
  477. {
  478. .callback = intel_no_lvds_dmi_callback,
  479. .ident = "Dell OptiPlex FX170",
  480. .matches = {
  481. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  482. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
  483. },
  484. },
  485. {
  486. .callback = intel_no_lvds_dmi_callback,
  487. .ident = "AOpen Mini PC",
  488. .matches = {
  489. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  490. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  491. },
  492. },
  493. {
  494. .callback = intel_no_lvds_dmi_callback,
  495. .ident = "AOpen Mini PC MP915",
  496. .matches = {
  497. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  498. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  499. },
  500. },
  501. {
  502. .callback = intel_no_lvds_dmi_callback,
  503. .ident = "AOpen i915GMm-HFS",
  504. .matches = {
  505. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  506. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  507. },
  508. },
  509. {
  510. .callback = intel_no_lvds_dmi_callback,
  511. .ident = "AOpen i45GMx-I",
  512. .matches = {
  513. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  514. DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
  515. },
  516. },
  517. {
  518. .callback = intel_no_lvds_dmi_callback,
  519. .ident = "Aopen i945GTt-VFA",
  520. .matches = {
  521. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  522. },
  523. },
  524. {
  525. .callback = intel_no_lvds_dmi_callback,
  526. .ident = "Clientron U800",
  527. .matches = {
  528. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  529. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  530. },
  531. },
  532. {
  533. .callback = intel_no_lvds_dmi_callback,
  534. .ident = "Clientron E830",
  535. .matches = {
  536. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  537. DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
  538. },
  539. },
  540. {
  541. .callback = intel_no_lvds_dmi_callback,
  542. .ident = "Asus EeeBox PC EB1007",
  543. .matches = {
  544. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  545. DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
  546. },
  547. },
  548. {
  549. .callback = intel_no_lvds_dmi_callback,
  550. .ident = "Asus AT5NM10T-I",
  551. .matches = {
  552. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  553. DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
  554. },
  555. },
  556. {
  557. .callback = intel_no_lvds_dmi_callback,
  558. .ident = "Hewlett-Packard HP t5740",
  559. .matches = {
  560. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  561. DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
  562. },
  563. },
  564. {
  565. .callback = intel_no_lvds_dmi_callback,
  566. .ident = "Hewlett-Packard t5745",
  567. .matches = {
  568. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  569. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
  570. },
  571. },
  572. {
  573. .callback = intel_no_lvds_dmi_callback,
  574. .ident = "Hewlett-Packard st5747",
  575. .matches = {
  576. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  577. DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
  578. },
  579. },
  580. {
  581. .callback = intel_no_lvds_dmi_callback,
  582. .ident = "MSI Wind Box DC500",
  583. .matches = {
  584. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  585. DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
  586. },
  587. },
  588. {
  589. .callback = intel_no_lvds_dmi_callback,
  590. .ident = "Gigabyte GA-D525TUD",
  591. .matches = {
  592. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  593. DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
  594. },
  595. },
  596. {
  597. .callback = intel_no_lvds_dmi_callback,
  598. .ident = "Supermicro X7SPA-H",
  599. .matches = {
  600. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  601. DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
  602. },
  603. },
  604. {
  605. .callback = intel_no_lvds_dmi_callback,
  606. .ident = "Fujitsu Esprimo Q900",
  607. .matches = {
  608. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  609. DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
  610. },
  611. },
  612. {
  613. .callback = intel_no_lvds_dmi_callback,
  614. .ident = "Intel D510MO",
  615. .matches = {
  616. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  617. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
  618. },
  619. },
  620. {
  621. .callback = intel_no_lvds_dmi_callback,
  622. .ident = "Intel D525MW",
  623. .matches = {
  624. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  625. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
  626. },
  627. },
  628. { } /* terminating entry */
  629. };
  630. /**
  631. * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
  632. * @dev: drm device
  633. * @connector: LVDS connector
  634. *
  635. * Find the reduced downclock for LVDS in EDID.
  636. */
  637. static void intel_find_lvds_downclock(struct drm_device *dev,
  638. struct drm_display_mode *fixed_mode,
  639. struct drm_connector *connector)
  640. {
  641. struct drm_i915_private *dev_priv = dev->dev_private;
  642. struct drm_display_mode *scan;
  643. int temp_downclock;
  644. temp_downclock = fixed_mode->clock;
  645. list_for_each_entry(scan, &connector->probed_modes, head) {
  646. /*
  647. * If one mode has the same resolution with the fixed_panel
  648. * mode while they have the different refresh rate, it means
  649. * that the reduced downclock is found for the LVDS. In such
  650. * case we can set the different FPx0/1 to dynamically select
  651. * between low and high frequency.
  652. */
  653. if (scan->hdisplay == fixed_mode->hdisplay &&
  654. scan->hsync_start == fixed_mode->hsync_start &&
  655. scan->hsync_end == fixed_mode->hsync_end &&
  656. scan->htotal == fixed_mode->htotal &&
  657. scan->vdisplay == fixed_mode->vdisplay &&
  658. scan->vsync_start == fixed_mode->vsync_start &&
  659. scan->vsync_end == fixed_mode->vsync_end &&
  660. scan->vtotal == fixed_mode->vtotal) {
  661. if (scan->clock < temp_downclock) {
  662. /*
  663. * The downclock is already found. But we
  664. * expect to find the lower downclock.
  665. */
  666. temp_downclock = scan->clock;
  667. }
  668. }
  669. }
  670. if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {
  671. /* We found the downclock for LVDS. */
  672. dev_priv->lvds_downclock_avail = 1;
  673. dev_priv->lvds_downclock = temp_downclock;
  674. DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
  675. "Normal clock %dKhz, downclock %dKhz\n",
  676. fixed_mode->clock, temp_downclock);
  677. }
  678. }
  679. /*
  680. * Enumerate the child dev array parsed from VBT to check whether
  681. * the LVDS is present.
  682. * If it is present, return 1.
  683. * If it is not present, return false.
  684. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  685. */
  686. static bool lvds_is_present_in_vbt(struct drm_device *dev,
  687. u8 *i2c_pin)
  688. {
  689. struct drm_i915_private *dev_priv = dev->dev_private;
  690. int i;
  691. if (!dev_priv->vbt.child_dev_num)
  692. return true;
  693. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  694. struct child_device_config *child = dev_priv->vbt.child_dev + i;
  695. /* If the device type is not LFP, continue.
  696. * We have to check both the new identifiers as well as the
  697. * old for compatibility with some BIOSes.
  698. */
  699. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  700. child->device_type != DEVICE_TYPE_LFP)
  701. continue;
  702. if (intel_gmbus_is_port_valid(child->i2c_pin))
  703. *i2c_pin = child->i2c_pin;
  704. /* However, we cannot trust the BIOS writers to populate
  705. * the VBT correctly. Since LVDS requires additional
  706. * information from AIM blocks, a non-zero addin offset is
  707. * a good indicator that the LVDS is actually present.
  708. */
  709. if (child->addin_offset)
  710. return true;
  711. /* But even then some BIOS writers perform some black magic
  712. * and instantiate the device without reference to any
  713. * additional data. Trust that if the VBT was written into
  714. * the OpRegion then they have validated the LVDS's existence.
  715. */
  716. if (dev_priv->opregion.vbt)
  717. return true;
  718. }
  719. return false;
  720. }
  721. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  722. {
  723. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  724. return 1;
  725. }
  726. static const struct dmi_system_id intel_dual_link_lvds[] = {
  727. {
  728. .callback = intel_dual_link_lvds_callback,
  729. .ident = "Apple MacBook Pro (Core i5/i7 Series)",
  730. .matches = {
  731. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  732. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  733. },
  734. },
  735. { } /* terminating entry */
  736. };
  737. bool intel_is_dual_link_lvds(struct drm_device *dev)
  738. {
  739. struct intel_encoder *encoder;
  740. struct intel_lvds_encoder *lvds_encoder;
  741. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  742. base.head) {
  743. if (encoder->type == INTEL_OUTPUT_LVDS) {
  744. lvds_encoder = to_lvds_encoder(&encoder->base);
  745. return lvds_encoder->is_dual_link;
  746. }
  747. }
  748. return false;
  749. }
  750. static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
  751. {
  752. struct drm_device *dev = lvds_encoder->base.base.dev;
  753. unsigned int val;
  754. struct drm_i915_private *dev_priv = dev->dev_private;
  755. /* use the module option value if specified */
  756. if (i915_lvds_channel_mode > 0)
  757. return i915_lvds_channel_mode == 2;
  758. if (dmi_check_system(intel_dual_link_lvds))
  759. return true;
  760. /* BIOS should set the proper LVDS register value at boot, but
  761. * in reality, it doesn't set the value when the lid is closed;
  762. * we need to check "the value to be set" in VBT when LVDS
  763. * register is uninitialized.
  764. */
  765. val = I915_READ(lvds_encoder->reg);
  766. if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
  767. val = dev_priv->vbt.bios_lvds_val;
  768. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  769. }
  770. static bool intel_lvds_supported(struct drm_device *dev)
  771. {
  772. /* With the introduction of the PCH we gained a dedicated
  773. * LVDS presence pin, use it. */
  774. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  775. return true;
  776. /* Otherwise LVDS was only attached to mobile products,
  777. * except for the inglorious 830gm */
  778. if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
  779. return true;
  780. return false;
  781. }
  782. /**
  783. * intel_lvds_init - setup LVDS connectors on this device
  784. * @dev: drm device
  785. *
  786. * Create the connector, register the LVDS DDC bus, and try to figure out what
  787. * modes we can display on the LVDS panel (if present).
  788. */
  789. void intel_lvds_init(struct drm_device *dev)
  790. {
  791. struct drm_i915_private *dev_priv = dev->dev_private;
  792. struct intel_lvds_encoder *lvds_encoder;
  793. struct intel_encoder *intel_encoder;
  794. struct intel_lvds_connector *lvds_connector;
  795. struct intel_connector *intel_connector;
  796. struct drm_connector *connector;
  797. struct drm_encoder *encoder;
  798. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  799. struct drm_display_mode *fixed_mode = NULL;
  800. struct edid *edid;
  801. struct drm_crtc *crtc;
  802. u32 lvds;
  803. int pipe;
  804. u8 pin;
  805. if (!intel_lvds_supported(dev))
  806. return;
  807. /* Skip init on machines we know falsely report LVDS */
  808. if (dmi_check_system(intel_no_lvds))
  809. return;
  810. pin = GMBUS_PORT_PANEL;
  811. if (!lvds_is_present_in_vbt(dev, &pin)) {
  812. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  813. return;
  814. }
  815. if (HAS_PCH_SPLIT(dev)) {
  816. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  817. return;
  818. if (dev_priv->vbt.edp_support) {
  819. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  820. return;
  821. }
  822. }
  823. lvds_encoder = kzalloc(sizeof(struct intel_lvds_encoder), GFP_KERNEL);
  824. if (!lvds_encoder)
  825. return;
  826. lvds_connector = kzalloc(sizeof(struct intel_lvds_connector), GFP_KERNEL);
  827. if (!lvds_connector) {
  828. kfree(lvds_encoder);
  829. return;
  830. }
  831. lvds_encoder->attached_connector = lvds_connector;
  832. intel_encoder = &lvds_encoder->base;
  833. encoder = &intel_encoder->base;
  834. intel_connector = &lvds_connector->base;
  835. connector = &intel_connector->base;
  836. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  837. DRM_MODE_CONNECTOR_LVDS);
  838. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  839. DRM_MODE_ENCODER_LVDS);
  840. intel_encoder->enable = intel_enable_lvds;
  841. intel_encoder->pre_pll_enable = intel_pre_pll_enable_lvds;
  842. intel_encoder->compute_config = intel_lvds_compute_config;
  843. intel_encoder->disable = intel_disable_lvds;
  844. intel_encoder->get_hw_state = intel_lvds_get_hw_state;
  845. intel_encoder->get_config = intel_lvds_get_config;
  846. intel_connector->get_hw_state = intel_connector_get_hw_state;
  847. intel_connector_attach_encoder(intel_connector, intel_encoder);
  848. intel_encoder->type = INTEL_OUTPUT_LVDS;
  849. intel_encoder->cloneable = false;
  850. if (HAS_PCH_SPLIT(dev))
  851. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  852. else if (IS_GEN4(dev))
  853. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  854. else
  855. intel_encoder->crtc_mask = (1 << 1);
  856. drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
  857. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  858. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  859. connector->interlace_allowed = false;
  860. connector->doublescan_allowed = false;
  861. if (HAS_PCH_SPLIT(dev)) {
  862. lvds_encoder->reg = PCH_LVDS;
  863. } else {
  864. lvds_encoder->reg = LVDS;
  865. }
  866. /* create the scaling mode property */
  867. drm_mode_create_scaling_mode_property(dev);
  868. drm_object_attach_property(&connector->base,
  869. dev->mode_config.scaling_mode_property,
  870. DRM_MODE_SCALE_ASPECT);
  871. intel_connector->panel.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. edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
  886. if (edid) {
  887. if (drm_add_edid_modes(connector, edid)) {
  888. drm_mode_connector_update_edid_property(connector,
  889. edid);
  890. } else {
  891. kfree(edid);
  892. edid = ERR_PTR(-EINVAL);
  893. }
  894. } else {
  895. edid = ERR_PTR(-ENOENT);
  896. }
  897. lvds_connector->base.edid = edid;
  898. if (IS_ERR_OR_NULL(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. DRM_DEBUG_KMS("using preferred mode from EDID: ");
  911. drm_mode_debug_printmodeline(scan);
  912. fixed_mode = drm_mode_duplicate(dev, scan);
  913. if (fixed_mode) {
  914. intel_find_lvds_downclock(dev, fixed_mode,
  915. connector);
  916. goto out;
  917. }
  918. }
  919. }
  920. /* Failed to get EDID, what about VBT? */
  921. if (dev_priv->vbt.lfp_lvds_vbt_mode) {
  922. DRM_DEBUG_KMS("using mode from VBT: ");
  923. drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
  924. fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
  925. if (fixed_mode) {
  926. 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. fixed_mode = intel_crtc_mode_get(dev, crtc);
  943. if (fixed_mode) {
  944. DRM_DEBUG_KMS("using current (BIOS) mode: ");
  945. drm_mode_debug_printmodeline(fixed_mode);
  946. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  947. goto out;
  948. }
  949. }
  950. /* If we still don't have a mode after all that, give up. */
  951. if (!fixed_mode)
  952. goto failed;
  953. out:
  954. lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
  955. DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
  956. lvds_encoder->is_dual_link ? "dual" : "single");
  957. /*
  958. * Unlock registers and just
  959. * leave them unlocked
  960. */
  961. if (HAS_PCH_SPLIT(dev)) {
  962. I915_WRITE(PCH_PP_CONTROL,
  963. I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
  964. } else {
  965. I915_WRITE(PP_CONTROL,
  966. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  967. }
  968. lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
  969. if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
  970. DRM_DEBUG_KMS("lid notifier registration failed\n");
  971. lvds_connector->lid_notifier.notifier_call = NULL;
  972. }
  973. drm_sysfs_connector_add(connector);
  974. intel_panel_init(&intel_connector->panel, fixed_mode);
  975. intel_panel_setup_backlight(connector);
  976. return;
  977. failed:
  978. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  979. drm_connector_cleanup(connector);
  980. drm_encoder_cleanup(encoder);
  981. if (fixed_mode)
  982. drm_mode_destroy(dev, fixed_mode);
  983. kfree(lvds_encoder);
  984. kfree(lvds_connector);
  985. return;
  986. }