intel_lvds.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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 <linux/dmi.h>
  30. #include <linux/i2c.h>
  31. #include "drmP.h"
  32. #include "drm.h"
  33. #include "drm_crtc.h"
  34. #include "drm_edid.h"
  35. #include "intel_drv.h"
  36. #include "i915_drm.h"
  37. #include "i915_drv.h"
  38. /**
  39. * Sets the backlight level.
  40. *
  41. * \param level backlight level, from 0 to intel_lvds_get_max_backlight().
  42. */
  43. static void intel_lvds_set_backlight(struct drm_device *dev, int level)
  44. {
  45. struct drm_i915_private *dev_priv = dev->dev_private;
  46. u32 blc_pwm_ctl, reg;
  47. if (IS_IGDNG(dev))
  48. reg = BLC_PWM_CPU_CTL;
  49. else
  50. reg = BLC_PWM_CTL;
  51. blc_pwm_ctl = I915_READ(reg) & ~BACKLIGHT_DUTY_CYCLE_MASK;
  52. I915_WRITE(reg, (blc_pwm_ctl |
  53. (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
  54. }
  55. /**
  56. * Returns the maximum level of the backlight duty cycle field.
  57. */
  58. static u32 intel_lvds_get_max_backlight(struct drm_device *dev)
  59. {
  60. struct drm_i915_private *dev_priv = dev->dev_private;
  61. u32 reg;
  62. if (IS_IGDNG(dev))
  63. reg = BLC_PWM_PCH_CTL2;
  64. else
  65. reg = BLC_PWM_CTL;
  66. return ((I915_READ(reg) & BACKLIGHT_MODULATION_FREQ_MASK) >>
  67. BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
  68. }
  69. /**
  70. * Sets the power state for the panel.
  71. */
  72. static void intel_lvds_set_power(struct drm_device *dev, bool on)
  73. {
  74. struct drm_i915_private *dev_priv = dev->dev_private;
  75. u32 pp_status, ctl_reg, status_reg;
  76. if (IS_IGDNG(dev)) {
  77. ctl_reg = PCH_PP_CONTROL;
  78. status_reg = PCH_PP_STATUS;
  79. } else {
  80. ctl_reg = PP_CONTROL;
  81. status_reg = PP_STATUS;
  82. }
  83. if (on) {
  84. I915_WRITE(ctl_reg, I915_READ(ctl_reg) |
  85. POWER_TARGET_ON);
  86. do {
  87. pp_status = I915_READ(status_reg);
  88. } while ((pp_status & PP_ON) == 0);
  89. intel_lvds_set_backlight(dev, dev_priv->backlight_duty_cycle);
  90. } else {
  91. intel_lvds_set_backlight(dev, 0);
  92. I915_WRITE(ctl_reg, I915_READ(ctl_reg) &
  93. ~POWER_TARGET_ON);
  94. do {
  95. pp_status = I915_READ(status_reg);
  96. } while (pp_status & PP_ON);
  97. }
  98. }
  99. static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
  100. {
  101. struct drm_device *dev = encoder->dev;
  102. if (mode == DRM_MODE_DPMS_ON)
  103. intel_lvds_set_power(dev, true);
  104. else
  105. intel_lvds_set_power(dev, false);
  106. /* XXX: We never power down the LVDS pairs. */
  107. }
  108. static void intel_lvds_save(struct drm_connector *connector)
  109. {
  110. struct drm_device *dev = connector->dev;
  111. struct drm_i915_private *dev_priv = dev->dev_private;
  112. u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg;
  113. u32 pwm_ctl_reg;
  114. if (IS_IGDNG(dev)) {
  115. pp_on_reg = PCH_PP_ON_DELAYS;
  116. pp_off_reg = PCH_PP_OFF_DELAYS;
  117. pp_ctl_reg = PCH_PP_CONTROL;
  118. pp_div_reg = PCH_PP_DIVISOR;
  119. pwm_ctl_reg = BLC_PWM_CPU_CTL;
  120. } else {
  121. pp_on_reg = PP_ON_DELAYS;
  122. pp_off_reg = PP_OFF_DELAYS;
  123. pp_ctl_reg = PP_CONTROL;
  124. pp_div_reg = PP_DIVISOR;
  125. pwm_ctl_reg = BLC_PWM_CTL;
  126. }
  127. dev_priv->savePP_ON = I915_READ(pp_on_reg);
  128. dev_priv->savePP_OFF = I915_READ(pp_off_reg);
  129. dev_priv->savePP_CONTROL = I915_READ(pp_ctl_reg);
  130. dev_priv->savePP_DIVISOR = I915_READ(pp_div_reg);
  131. dev_priv->saveBLC_PWM_CTL = I915_READ(pwm_ctl_reg);
  132. dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
  133. BACKLIGHT_DUTY_CYCLE_MASK);
  134. /*
  135. * If the light is off at server startup, just make it full brightness
  136. */
  137. if (dev_priv->backlight_duty_cycle == 0)
  138. dev_priv->backlight_duty_cycle =
  139. intel_lvds_get_max_backlight(dev);
  140. }
  141. static void intel_lvds_restore(struct drm_connector *connector)
  142. {
  143. struct drm_device *dev = connector->dev;
  144. struct drm_i915_private *dev_priv = dev->dev_private;
  145. u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg;
  146. u32 pwm_ctl_reg;
  147. if (IS_IGDNG(dev)) {
  148. pp_on_reg = PCH_PP_ON_DELAYS;
  149. pp_off_reg = PCH_PP_OFF_DELAYS;
  150. pp_ctl_reg = PCH_PP_CONTROL;
  151. pp_div_reg = PCH_PP_DIVISOR;
  152. pwm_ctl_reg = BLC_PWM_CPU_CTL;
  153. } else {
  154. pp_on_reg = PP_ON_DELAYS;
  155. pp_off_reg = PP_OFF_DELAYS;
  156. pp_ctl_reg = PP_CONTROL;
  157. pp_div_reg = PP_DIVISOR;
  158. pwm_ctl_reg = BLC_PWM_CTL;
  159. }
  160. I915_WRITE(pwm_ctl_reg, dev_priv->saveBLC_PWM_CTL);
  161. I915_WRITE(pp_on_reg, dev_priv->savePP_ON);
  162. I915_WRITE(pp_off_reg, dev_priv->savePP_OFF);
  163. I915_WRITE(pp_div_reg, dev_priv->savePP_DIVISOR);
  164. I915_WRITE(pp_ctl_reg, dev_priv->savePP_CONTROL);
  165. if (dev_priv->savePP_CONTROL & POWER_TARGET_ON)
  166. intel_lvds_set_power(dev, true);
  167. else
  168. intel_lvds_set_power(dev, false);
  169. }
  170. static int intel_lvds_mode_valid(struct drm_connector *connector,
  171. struct drm_display_mode *mode)
  172. {
  173. struct drm_device *dev = connector->dev;
  174. struct drm_i915_private *dev_priv = dev->dev_private;
  175. struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
  176. if (fixed_mode) {
  177. if (mode->hdisplay > fixed_mode->hdisplay)
  178. return MODE_PANEL;
  179. if (mode->vdisplay > fixed_mode->vdisplay)
  180. return MODE_PANEL;
  181. }
  182. return MODE_OK;
  183. }
  184. static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
  185. struct drm_display_mode *mode,
  186. struct drm_display_mode *adjusted_mode)
  187. {
  188. struct drm_device *dev = encoder->dev;
  189. struct drm_i915_private *dev_priv = dev->dev_private;
  190. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  191. struct drm_encoder *tmp_encoder;
  192. /* Should never happen!! */
  193. if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
  194. printk(KERN_ERR "Can't support LVDS on pipe A\n");
  195. return false;
  196. }
  197. /* Should never happen!! */
  198. list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
  199. if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
  200. printk(KERN_ERR "Can't enable LVDS and another "
  201. "encoder on the same pipe\n");
  202. return false;
  203. }
  204. }
  205. /*
  206. * If we have timings from the BIOS for the panel, put them in
  207. * to the adjusted mode. The CRTC will be set up for this mode,
  208. * with the panel scaling set up to source from the H/VDisplay
  209. * of the original mode.
  210. */
  211. if (dev_priv->panel_fixed_mode != NULL) {
  212. adjusted_mode->hdisplay = dev_priv->panel_fixed_mode->hdisplay;
  213. adjusted_mode->hsync_start =
  214. dev_priv->panel_fixed_mode->hsync_start;
  215. adjusted_mode->hsync_end =
  216. dev_priv->panel_fixed_mode->hsync_end;
  217. adjusted_mode->htotal = dev_priv->panel_fixed_mode->htotal;
  218. adjusted_mode->vdisplay = dev_priv->panel_fixed_mode->vdisplay;
  219. adjusted_mode->vsync_start =
  220. dev_priv->panel_fixed_mode->vsync_start;
  221. adjusted_mode->vsync_end =
  222. dev_priv->panel_fixed_mode->vsync_end;
  223. adjusted_mode->vtotal = dev_priv->panel_fixed_mode->vtotal;
  224. adjusted_mode->clock = dev_priv->panel_fixed_mode->clock;
  225. drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
  226. }
  227. /*
  228. * XXX: It would be nice to support lower refresh rates on the
  229. * panels to reduce power consumption, and perhaps match the
  230. * user's requested refresh rate.
  231. */
  232. return true;
  233. }
  234. static void intel_lvds_prepare(struct drm_encoder *encoder)
  235. {
  236. struct drm_device *dev = encoder->dev;
  237. struct drm_i915_private *dev_priv = dev->dev_private;
  238. u32 reg;
  239. if (IS_IGDNG(dev))
  240. reg = BLC_PWM_CPU_CTL;
  241. else
  242. reg = BLC_PWM_CTL;
  243. dev_priv->saveBLC_PWM_CTL = I915_READ(reg);
  244. dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
  245. BACKLIGHT_DUTY_CYCLE_MASK);
  246. intel_lvds_set_power(dev, false);
  247. }
  248. static void intel_lvds_commit( struct drm_encoder *encoder)
  249. {
  250. struct drm_device *dev = encoder->dev;
  251. struct drm_i915_private *dev_priv = dev->dev_private;
  252. if (dev_priv->backlight_duty_cycle == 0)
  253. dev_priv->backlight_duty_cycle =
  254. intel_lvds_get_max_backlight(dev);
  255. intel_lvds_set_power(dev, true);
  256. }
  257. static void intel_lvds_mode_set(struct drm_encoder *encoder,
  258. struct drm_display_mode *mode,
  259. struct drm_display_mode *adjusted_mode)
  260. {
  261. struct drm_device *dev = encoder->dev;
  262. struct drm_i915_private *dev_priv = dev->dev_private;
  263. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  264. u32 pfit_control;
  265. /*
  266. * The LVDS pin pair will already have been turned on in the
  267. * intel_crtc_mode_set since it has a large impact on the DPLL
  268. * settings.
  269. */
  270. /* No panel fitting yet, fixme */
  271. if (IS_IGDNG(dev))
  272. return;
  273. /*
  274. * Enable automatic panel scaling so that non-native modes fill the
  275. * screen. Should be enabled before the pipe is enabled, according to
  276. * register description and PRM.
  277. */
  278. if (mode->hdisplay != adjusted_mode->hdisplay ||
  279. mode->vdisplay != adjusted_mode->vdisplay)
  280. pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
  281. HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
  282. HORIZ_INTERP_BILINEAR);
  283. else
  284. pfit_control = 0;
  285. if (!IS_I965G(dev)) {
  286. if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
  287. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  288. }
  289. else
  290. pfit_control |= intel_crtc->pipe << PFIT_PIPE_SHIFT;
  291. I915_WRITE(PFIT_CONTROL, pfit_control);
  292. }
  293. /**
  294. * Detect the LVDS connection.
  295. *
  296. * This always returns CONNECTOR_STATUS_CONNECTED. This connector should only have
  297. * been set up if the LVDS was actually connected anyway.
  298. */
  299. static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector)
  300. {
  301. return connector_status_connected;
  302. }
  303. /**
  304. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  305. */
  306. static int intel_lvds_get_modes(struct drm_connector *connector)
  307. {
  308. struct drm_device *dev = connector->dev;
  309. struct intel_output *intel_output = to_intel_output(connector);
  310. struct drm_i915_private *dev_priv = dev->dev_private;
  311. int ret = 0;
  312. ret = intel_ddc_get_modes(intel_output);
  313. if (ret)
  314. return ret;
  315. /* Didn't get an EDID, so
  316. * Set wide sync ranges so we get all modes
  317. * handed to valid_mode for checking
  318. */
  319. connector->display_info.min_vfreq = 0;
  320. connector->display_info.max_vfreq = 200;
  321. connector->display_info.min_hfreq = 0;
  322. connector->display_info.max_hfreq = 200;
  323. if (dev_priv->panel_fixed_mode != NULL) {
  324. struct drm_display_mode *mode;
  325. mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
  326. drm_mode_probed_add(connector, mode);
  327. return 1;
  328. }
  329. return 0;
  330. }
  331. /**
  332. * intel_lvds_destroy - unregister and free LVDS structures
  333. * @connector: connector to free
  334. *
  335. * Unregister the DDC bus for this connector then free the driver private
  336. * structure.
  337. */
  338. static void intel_lvds_destroy(struct drm_connector *connector)
  339. {
  340. struct intel_output *intel_output = to_intel_output(connector);
  341. if (intel_output->ddc_bus)
  342. intel_i2c_destroy(intel_output->ddc_bus);
  343. drm_sysfs_connector_remove(connector);
  344. drm_connector_cleanup(connector);
  345. kfree(connector);
  346. }
  347. static int intel_lvds_set_property(struct drm_connector *connector,
  348. struct drm_property *property,
  349. uint64_t value)
  350. {
  351. struct drm_device *dev = connector->dev;
  352. if (property == dev->mode_config.dpms_property && connector->encoder)
  353. intel_lvds_dpms(connector->encoder, (uint32_t)(value & 0xf));
  354. return 0;
  355. }
  356. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  357. .dpms = intel_lvds_dpms,
  358. .mode_fixup = intel_lvds_mode_fixup,
  359. .prepare = intel_lvds_prepare,
  360. .mode_set = intel_lvds_mode_set,
  361. .commit = intel_lvds_commit,
  362. };
  363. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  364. .get_modes = intel_lvds_get_modes,
  365. .mode_valid = intel_lvds_mode_valid,
  366. .best_encoder = intel_best_encoder,
  367. };
  368. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  369. .save = intel_lvds_save,
  370. .restore = intel_lvds_restore,
  371. .detect = intel_lvds_detect,
  372. .fill_modes = drm_helper_probe_single_connector_modes,
  373. .set_property = intel_lvds_set_property,
  374. .destroy = intel_lvds_destroy,
  375. };
  376. static void intel_lvds_enc_destroy(struct drm_encoder *encoder)
  377. {
  378. drm_encoder_cleanup(encoder);
  379. }
  380. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  381. .destroy = intel_lvds_enc_destroy,
  382. };
  383. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  384. {
  385. DRM_DEBUG("Skipping LVDS initialization for %s\n", id->ident);
  386. return 1;
  387. }
  388. /* These systems claim to have LVDS, but really don't */
  389. static const struct dmi_system_id __initdata intel_no_lvds[] = {
  390. {
  391. .callback = intel_no_lvds_dmi_callback,
  392. .ident = "Apple Mac Mini (Core series)",
  393. .matches = {
  394. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  395. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  396. },
  397. },
  398. {
  399. .callback = intel_no_lvds_dmi_callback,
  400. .ident = "Apple Mac Mini (Core 2 series)",
  401. .matches = {
  402. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  403. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  404. },
  405. },
  406. {
  407. .callback = intel_no_lvds_dmi_callback,
  408. .ident = "MSI IM-945GSE-A",
  409. .matches = {
  410. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  411. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  412. },
  413. },
  414. {
  415. .callback = intel_no_lvds_dmi_callback,
  416. .ident = "Dell Studio Hybrid",
  417. .matches = {
  418. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  419. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  420. },
  421. },
  422. {
  423. .callback = intel_no_lvds_dmi_callback,
  424. .ident = "AOpen Mini PC",
  425. .matches = {
  426. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  427. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  428. },
  429. },
  430. {
  431. .callback = intel_no_lvds_dmi_callback,
  432. .ident = "Aopen i945GTt-VFA",
  433. .matches = {
  434. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  435. },
  436. },
  437. { } /* terminating entry */
  438. };
  439. /**
  440. * intel_lvds_init - setup LVDS connectors on this device
  441. * @dev: drm device
  442. *
  443. * Create the connector, register the LVDS DDC bus, and try to figure out what
  444. * modes we can display on the LVDS panel (if present).
  445. */
  446. void intel_lvds_init(struct drm_device *dev)
  447. {
  448. struct drm_i915_private *dev_priv = dev->dev_private;
  449. struct intel_output *intel_output;
  450. struct drm_connector *connector;
  451. struct drm_encoder *encoder;
  452. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  453. struct drm_crtc *crtc;
  454. u32 lvds;
  455. int pipe, gpio = GPIOC;
  456. /* Skip init on machines we know falsely report LVDS */
  457. if (dmi_check_system(intel_no_lvds))
  458. return;
  459. if (IS_IGDNG(dev)) {
  460. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  461. return;
  462. gpio = PCH_GPIOC;
  463. }
  464. intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
  465. if (!intel_output) {
  466. return;
  467. }
  468. connector = &intel_output->base;
  469. encoder = &intel_output->enc;
  470. drm_connector_init(dev, &intel_output->base, &intel_lvds_connector_funcs,
  471. DRM_MODE_CONNECTOR_LVDS);
  472. drm_encoder_init(dev, &intel_output->enc, &intel_lvds_enc_funcs,
  473. DRM_MODE_ENCODER_LVDS);
  474. drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc);
  475. intel_output->type = INTEL_OUTPUT_LVDS;
  476. drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
  477. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  478. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  479. connector->interlace_allowed = false;
  480. connector->doublescan_allowed = false;
  481. /*
  482. * LVDS discovery:
  483. * 1) check for EDID on DDC
  484. * 2) check for VBT data
  485. * 3) check to see if LVDS is already on
  486. * if none of the above, no panel
  487. * 4) make sure lid is open
  488. * if closed, act like it's not there for now
  489. */
  490. /* Set up the DDC bus. */
  491. intel_output->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C");
  492. if (!intel_output->ddc_bus) {
  493. dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
  494. "failed.\n");
  495. goto failed;
  496. }
  497. /*
  498. * Attempt to get the fixed panel mode from DDC. Assume that the
  499. * preferred mode is the right one.
  500. */
  501. intel_ddc_get_modes(intel_output);
  502. list_for_each_entry(scan, &connector->probed_modes, head) {
  503. mutex_lock(&dev->mode_config.mutex);
  504. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  505. dev_priv->panel_fixed_mode =
  506. drm_mode_duplicate(dev, scan);
  507. mutex_unlock(&dev->mode_config.mutex);
  508. goto out;
  509. }
  510. mutex_unlock(&dev->mode_config.mutex);
  511. }
  512. /* Failed to get EDID, what about VBT? */
  513. if (dev_priv->lfp_lvds_vbt_mode) {
  514. mutex_lock(&dev->mode_config.mutex);
  515. dev_priv->panel_fixed_mode =
  516. drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  517. mutex_unlock(&dev->mode_config.mutex);
  518. if (dev_priv->panel_fixed_mode) {
  519. dev_priv->panel_fixed_mode->type |=
  520. DRM_MODE_TYPE_PREFERRED;
  521. goto out;
  522. }
  523. }
  524. /*
  525. * If we didn't get EDID, try checking if the panel is already turned
  526. * on. If so, assume that whatever is currently programmed is the
  527. * correct mode.
  528. */
  529. /* IGDNG: FIXME if still fail, not try pipe mode now */
  530. if (IS_IGDNG(dev))
  531. goto failed;
  532. lvds = I915_READ(LVDS);
  533. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  534. crtc = intel_get_crtc_from_pipe(dev, pipe);
  535. if (crtc && (lvds & LVDS_PORT_EN)) {
  536. dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc);
  537. if (dev_priv->panel_fixed_mode) {
  538. dev_priv->panel_fixed_mode->type |=
  539. DRM_MODE_TYPE_PREFERRED;
  540. goto out;
  541. }
  542. }
  543. /* If we still don't have a mode after all that, give up. */
  544. if (!dev_priv->panel_fixed_mode)
  545. goto failed;
  546. out:
  547. if (IS_IGDNG(dev)) {
  548. u32 pwm;
  549. /* make sure PWM is enabled */
  550. pwm = I915_READ(BLC_PWM_CPU_CTL2);
  551. pwm |= (PWM_ENABLE | PWM_PIPE_B);
  552. I915_WRITE(BLC_PWM_CPU_CTL2, pwm);
  553. pwm = I915_READ(BLC_PWM_PCH_CTL1);
  554. pwm |= PWM_PCH_ENABLE;
  555. I915_WRITE(BLC_PWM_PCH_CTL1, pwm);
  556. }
  557. drm_sysfs_connector_add(connector);
  558. return;
  559. failed:
  560. DRM_DEBUG("No LVDS modes found, disabling.\n");
  561. if (intel_output->ddc_bus)
  562. intel_i2c_destroy(intel_output->ddc_bus);
  563. drm_connector_cleanup(connector);
  564. kfree(connector);
  565. }