cdv_intel_lvds.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright © 2006-2011 Intel Corporation
  4. *
  5. * Authors:
  6. * Eric Anholt <eric@anholt.net>
  7. * Dave Airlie <airlied@linux.ie>
  8. * Jesse Barnes <jesse.barnes@intel.com>
  9. */
  10. #include <linux/dmi.h>
  11. #include <linux/i2c.h>
  12. #include <linux/pm_runtime.h>
  13. #include <drm/drm_crtc_helper.h>
  14. #include <drm/drm_modeset_helper_vtables.h>
  15. #include <drm/drm_simple_kms_helper.h>
  16. #include "cdv_device.h"
  17. #include "intel_bios.h"
  18. #include "power.h"
  19. #include "psb_drv.h"
  20. #include "psb_intel_drv.h"
  21. #include "psb_intel_reg.h"
  22. /*
  23. * LVDS I2C backlight control macros
  24. */
  25. #define BRIGHTNESS_MAX_LEVEL 100
  26. #define BRIGHTNESS_MASK 0xFF
  27. #define BLC_I2C_TYPE 0x01
  28. #define BLC_PWM_TYPT 0x02
  29. #define BLC_POLARITY_NORMAL 0
  30. #define BLC_POLARITY_INVERSE 1
  31. #define PSB_BLC_MAX_PWM_REG_FREQ (0xFFFE)
  32. #define PSB_BLC_MIN_PWM_REG_FREQ (0x2)
  33. #define PSB_BLC_PWM_PRECISION_FACTOR (10)
  34. #define PSB_BACKLIGHT_PWM_CTL_SHIFT (16)
  35. #define PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR (0xFFFE)
  36. struct cdv_intel_lvds_priv {
  37. /**
  38. * Saved LVDO output states
  39. */
  40. uint32_t savePP_ON;
  41. uint32_t savePP_OFF;
  42. uint32_t saveLVDS;
  43. uint32_t savePP_CONTROL;
  44. uint32_t savePP_CYCLE;
  45. uint32_t savePFIT_CONTROL;
  46. uint32_t savePFIT_PGM_RATIOS;
  47. uint32_t saveBLC_PWM_CTL;
  48. };
  49. /*
  50. * Returns the maximum level of the backlight duty cycle field.
  51. */
  52. static u32 cdv_intel_lvds_get_max_backlight(struct drm_device *dev)
  53. {
  54. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  55. u32 retval;
  56. if (gma_power_begin(dev, false)) {
  57. retval = ((REG_READ(BLC_PWM_CTL) &
  58. BACKLIGHT_MODULATION_FREQ_MASK) >>
  59. BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
  60. gma_power_end(dev);
  61. } else
  62. retval = ((dev_priv->regs.saveBLC_PWM_CTL &
  63. BACKLIGHT_MODULATION_FREQ_MASK) >>
  64. BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
  65. return retval;
  66. }
  67. /*
  68. * Sets the backlight level.
  69. *
  70. * level backlight level, from 0 to cdv_intel_lvds_get_max_backlight().
  71. */
  72. static void cdv_intel_lvds_set_backlight(struct drm_device *dev, int level)
  73. {
  74. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  75. u32 blc_pwm_ctl;
  76. if (gma_power_begin(dev, false)) {
  77. blc_pwm_ctl =
  78. REG_READ(BLC_PWM_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK;
  79. REG_WRITE(BLC_PWM_CTL,
  80. (blc_pwm_ctl |
  81. (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
  82. gma_power_end(dev);
  83. } else {
  84. blc_pwm_ctl = dev_priv->regs.saveBLC_PWM_CTL &
  85. ~BACKLIGHT_DUTY_CYCLE_MASK;
  86. dev_priv->regs.saveBLC_PWM_CTL = (blc_pwm_ctl |
  87. (level << BACKLIGHT_DUTY_CYCLE_SHIFT));
  88. }
  89. }
  90. /*
  91. * Sets the power state for the panel.
  92. */
  93. static void cdv_intel_lvds_set_power(struct drm_device *dev,
  94. struct drm_encoder *encoder, bool on)
  95. {
  96. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  97. u32 pp_status;
  98. if (!gma_power_begin(dev, true))
  99. return;
  100. if (on) {
  101. REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) |
  102. POWER_TARGET_ON);
  103. do {
  104. pp_status = REG_READ(PP_STATUS);
  105. } while ((pp_status & PP_ON) == 0);
  106. cdv_intel_lvds_set_backlight(dev,
  107. dev_priv->mode_dev.backlight_duty_cycle);
  108. } else {
  109. cdv_intel_lvds_set_backlight(dev, 0);
  110. REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) &
  111. ~POWER_TARGET_ON);
  112. do {
  113. pp_status = REG_READ(PP_STATUS);
  114. } while (pp_status & PP_ON);
  115. }
  116. gma_power_end(dev);
  117. }
  118. static void cdv_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode)
  119. {
  120. struct drm_device *dev = encoder->dev;
  121. if (mode == DRM_MODE_DPMS_ON)
  122. cdv_intel_lvds_set_power(dev, encoder, true);
  123. else
  124. cdv_intel_lvds_set_power(dev, encoder, false);
  125. /* XXX: We never power down the LVDS pairs. */
  126. }
  127. static void cdv_intel_lvds_save(struct drm_connector *connector)
  128. {
  129. }
  130. static void cdv_intel_lvds_restore(struct drm_connector *connector)
  131. {
  132. }
  133. static enum drm_mode_status cdv_intel_lvds_mode_valid(struct drm_connector *connector,
  134. struct drm_display_mode *mode)
  135. {
  136. struct drm_device *dev = connector->dev;
  137. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  138. struct drm_display_mode *fixed_mode =
  139. dev_priv->mode_dev.panel_fixed_mode;
  140. /* just in case */
  141. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  142. return MODE_NO_DBLESCAN;
  143. /* just in case */
  144. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  145. return MODE_NO_INTERLACE;
  146. if (fixed_mode) {
  147. if (mode->hdisplay > fixed_mode->hdisplay)
  148. return MODE_PANEL;
  149. if (mode->vdisplay > fixed_mode->vdisplay)
  150. return MODE_PANEL;
  151. }
  152. return MODE_OK;
  153. }
  154. static bool cdv_intel_lvds_mode_fixup(struct drm_encoder *encoder,
  155. const struct drm_display_mode *mode,
  156. struct drm_display_mode *adjusted_mode)
  157. {
  158. struct drm_device *dev = encoder->dev;
  159. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  160. struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
  161. struct drm_encoder *tmp_encoder;
  162. struct drm_display_mode *panel_fixed_mode = mode_dev->panel_fixed_mode;
  163. /* Should never happen!! */
  164. list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list,
  165. head) {
  166. if (tmp_encoder != encoder
  167. && tmp_encoder->crtc == encoder->crtc) {
  168. pr_err("Can't enable LVDS and another encoder on the same pipe\n");
  169. return false;
  170. }
  171. }
  172. /*
  173. * If we have timings from the BIOS for the panel, put them in
  174. * to the adjusted mode. The CRTC will be set up for this mode,
  175. * with the panel scaling set up to source from the H/VDisplay
  176. * of the original mode.
  177. */
  178. if (panel_fixed_mode != NULL) {
  179. adjusted_mode->hdisplay = panel_fixed_mode->hdisplay;
  180. adjusted_mode->hsync_start = panel_fixed_mode->hsync_start;
  181. adjusted_mode->hsync_end = panel_fixed_mode->hsync_end;
  182. adjusted_mode->htotal = panel_fixed_mode->htotal;
  183. adjusted_mode->vdisplay = panel_fixed_mode->vdisplay;
  184. adjusted_mode->vsync_start = panel_fixed_mode->vsync_start;
  185. adjusted_mode->vsync_end = panel_fixed_mode->vsync_end;
  186. adjusted_mode->vtotal = panel_fixed_mode->vtotal;
  187. adjusted_mode->clock = panel_fixed_mode->clock;
  188. drm_mode_set_crtcinfo(adjusted_mode,
  189. CRTC_INTERLACE_HALVE_V);
  190. }
  191. /*
  192. * XXX: It would be nice to support lower refresh rates on the
  193. * panels to reduce power consumption, and perhaps match the
  194. * user's requested refresh rate.
  195. */
  196. return true;
  197. }
  198. static void cdv_intel_lvds_prepare(struct drm_encoder *encoder)
  199. {
  200. struct drm_device *dev = encoder->dev;
  201. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  202. struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
  203. if (!gma_power_begin(dev, true))
  204. return;
  205. mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL);
  206. mode_dev->backlight_duty_cycle = (mode_dev->saveBLC_PWM_CTL &
  207. BACKLIGHT_DUTY_CYCLE_MASK);
  208. cdv_intel_lvds_set_power(dev, encoder, false);
  209. gma_power_end(dev);
  210. }
  211. static void cdv_intel_lvds_commit(struct drm_encoder *encoder)
  212. {
  213. struct drm_device *dev = encoder->dev;
  214. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  215. struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
  216. if (mode_dev->backlight_duty_cycle == 0)
  217. mode_dev->backlight_duty_cycle =
  218. cdv_intel_lvds_get_max_backlight(dev);
  219. cdv_intel_lvds_set_power(dev, encoder, true);
  220. }
  221. static void cdv_intel_lvds_mode_set(struct drm_encoder *encoder,
  222. struct drm_display_mode *mode,
  223. struct drm_display_mode *adjusted_mode)
  224. {
  225. struct drm_device *dev = encoder->dev;
  226. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  227. struct gma_crtc *gma_crtc = to_gma_crtc(encoder->crtc);
  228. u32 pfit_control;
  229. /*
  230. * The LVDS pin pair will already have been turned on in the
  231. * cdv_intel_crtc_mode_set since it has a large impact on the DPLL
  232. * settings.
  233. */
  234. /*
  235. * Enable automatic panel scaling so that non-native modes fill the
  236. * screen. Should be enabled before the pipe is enabled, according to
  237. * register description and PRM.
  238. */
  239. if (mode->hdisplay != adjusted_mode->hdisplay ||
  240. mode->vdisplay != adjusted_mode->vdisplay)
  241. pfit_control = (PFIT_ENABLE | VERT_AUTO_SCALE |
  242. HORIZ_AUTO_SCALE | VERT_INTERP_BILINEAR |
  243. HORIZ_INTERP_BILINEAR);
  244. else
  245. pfit_control = 0;
  246. pfit_control |= gma_crtc->pipe << PFIT_PIPE_SHIFT;
  247. if (dev_priv->lvds_dither)
  248. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  249. REG_WRITE(PFIT_CONTROL, pfit_control);
  250. }
  251. /*
  252. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  253. */
  254. static int cdv_intel_lvds_get_modes(struct drm_connector *connector)
  255. {
  256. struct drm_device *dev = connector->dev;
  257. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  258. struct psb_intel_mode_device *mode_dev = &dev_priv->mode_dev;
  259. int ret;
  260. ret = psb_intel_ddc_get_modes(connector, connector->ddc);
  261. if (ret)
  262. return ret;
  263. if (mode_dev->panel_fixed_mode != NULL) {
  264. struct drm_display_mode *mode =
  265. drm_mode_duplicate(dev, mode_dev->panel_fixed_mode);
  266. if (!mode)
  267. return 0;
  268. drm_mode_probed_add(connector, mode);
  269. return 1;
  270. }
  271. return 0;
  272. }
  273. static void cdv_intel_lvds_destroy(struct drm_connector *connector)
  274. {
  275. struct gma_connector *gma_connector = to_gma_connector(connector);
  276. struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
  277. gma_i2c_destroy(to_gma_i2c_chan(connector->ddc));
  278. gma_i2c_destroy(gma_encoder->i2c_bus);
  279. drm_connector_cleanup(connector);
  280. kfree(gma_connector);
  281. }
  282. static int cdv_intel_lvds_set_property(struct drm_connector *connector,
  283. struct drm_property *property,
  284. uint64_t value)
  285. {
  286. struct drm_encoder *encoder = connector->encoder;
  287. if (!strcmp(property->name, "scaling mode") && encoder) {
  288. struct gma_crtc *crtc = to_gma_crtc(encoder->crtc);
  289. uint64_t curValue;
  290. if (!crtc)
  291. return -1;
  292. switch (value) {
  293. case DRM_MODE_SCALE_FULLSCREEN:
  294. break;
  295. case DRM_MODE_SCALE_NO_SCALE:
  296. break;
  297. case DRM_MODE_SCALE_ASPECT:
  298. break;
  299. default:
  300. return -1;
  301. }
  302. if (drm_object_property_get_value(&connector->base,
  303. property,
  304. &curValue))
  305. return -1;
  306. if (curValue == value)
  307. return 0;
  308. if (drm_object_property_set_value(&connector->base,
  309. property,
  310. value))
  311. return -1;
  312. if (crtc->saved_mode.hdisplay != 0 &&
  313. crtc->saved_mode.vdisplay != 0) {
  314. if (!drm_crtc_helper_set_mode(encoder->crtc,
  315. &crtc->saved_mode,
  316. encoder->crtc->x,
  317. encoder->crtc->y,
  318. encoder->crtc->primary->fb))
  319. return -1;
  320. }
  321. } else if (!strcmp(property->name, "backlight") && encoder) {
  322. if (drm_object_property_set_value(&connector->base,
  323. property,
  324. value))
  325. return -1;
  326. else
  327. gma_backlight_set(encoder->dev, value);
  328. } else if (!strcmp(property->name, "DPMS") && encoder) {
  329. const struct drm_encoder_helper_funcs *helpers =
  330. encoder->helper_private;
  331. helpers->dpms(encoder, value);
  332. }
  333. return 0;
  334. }
  335. static const struct drm_encoder_helper_funcs
  336. cdv_intel_lvds_helper_funcs = {
  337. .dpms = cdv_intel_lvds_encoder_dpms,
  338. .mode_fixup = cdv_intel_lvds_mode_fixup,
  339. .prepare = cdv_intel_lvds_prepare,
  340. .mode_set = cdv_intel_lvds_mode_set,
  341. .commit = cdv_intel_lvds_commit,
  342. };
  343. static const struct drm_connector_helper_funcs
  344. cdv_intel_lvds_connector_helper_funcs = {
  345. .get_modes = cdv_intel_lvds_get_modes,
  346. .mode_valid = cdv_intel_lvds_mode_valid,
  347. .best_encoder = gma_best_encoder,
  348. };
  349. static const struct drm_connector_funcs cdv_intel_lvds_connector_funcs = {
  350. .dpms = drm_helper_connector_dpms,
  351. .fill_modes = drm_helper_probe_single_connector_modes,
  352. .set_property = cdv_intel_lvds_set_property,
  353. .destroy = cdv_intel_lvds_destroy,
  354. };
  355. /*
  356. * Enumerate the child dev array parsed from VBT to check whether
  357. * the LVDS is present.
  358. * If it is present, return 1.
  359. * If it is not present, return false.
  360. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  361. */
  362. static bool lvds_is_present_in_vbt(struct drm_device *dev,
  363. u8 *i2c_pin)
  364. {
  365. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  366. int i;
  367. if (!dev_priv->child_dev_num)
  368. return true;
  369. for (i = 0; i < dev_priv->child_dev_num; i++) {
  370. struct child_device_config *child = dev_priv->child_dev + i;
  371. /* If the device type is not LFP, continue.
  372. * We have to check both the new identifiers as well as the
  373. * old for compatibility with some BIOSes.
  374. */
  375. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  376. child->device_type != DEVICE_TYPE_LFP)
  377. continue;
  378. if (child->i2c_pin)
  379. *i2c_pin = child->i2c_pin;
  380. /* However, we cannot trust the BIOS writers to populate
  381. * the VBT correctly. Since LVDS requires additional
  382. * information from AIM blocks, a non-zero addin offset is
  383. * a good indicator that the LVDS is actually present.
  384. */
  385. if (child->addin_offset)
  386. return true;
  387. /* But even then some BIOS writers perform some black magic
  388. * and instantiate the device without reference to any
  389. * additional data. Trust that if the VBT was written into
  390. * the OpRegion then they have validated the LVDS's existence.
  391. */
  392. if (dev_priv->opregion.vbt)
  393. return true;
  394. }
  395. return false;
  396. }
  397. /**
  398. * cdv_intel_lvds_init - setup LVDS connectors on this device
  399. * @dev: drm device
  400. * @mode_dev: PSB mode device
  401. *
  402. * Create the connector, register the LVDS DDC bus, and try to figure out what
  403. * modes we can display on the LVDS panel (if present).
  404. */
  405. void cdv_intel_lvds_init(struct drm_device *dev,
  406. struct psb_intel_mode_device *mode_dev)
  407. {
  408. struct gma_encoder *gma_encoder;
  409. struct gma_connector *gma_connector;
  410. struct cdv_intel_lvds_priv *lvds_priv;
  411. struct drm_connector *connector;
  412. struct drm_encoder *encoder;
  413. struct drm_display_mode *scan;
  414. struct drm_crtc *crtc;
  415. struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
  416. struct gma_i2c_chan *ddc_bus;
  417. u32 lvds;
  418. int pipe;
  419. int ret;
  420. u8 pin;
  421. if (!dev_priv->lvds_enabled_in_vbt)
  422. return;
  423. pin = GMBUS_PORT_PANEL;
  424. if (!lvds_is_present_in_vbt(dev, &pin)) {
  425. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  426. return;
  427. }
  428. gma_encoder = kzalloc(sizeof(struct gma_encoder),
  429. GFP_KERNEL);
  430. if (!gma_encoder)
  431. return;
  432. gma_connector = kzalloc(sizeof(struct gma_connector),
  433. GFP_KERNEL);
  434. if (!gma_connector)
  435. goto err_free_encoder;
  436. lvds_priv = kzalloc(sizeof(struct cdv_intel_lvds_priv), GFP_KERNEL);
  437. if (!lvds_priv)
  438. goto err_free_connector;
  439. gma_encoder->dev_priv = lvds_priv;
  440. connector = &gma_connector->base;
  441. gma_connector->save = cdv_intel_lvds_save;
  442. gma_connector->restore = cdv_intel_lvds_restore;
  443. encoder = &gma_encoder->base;
  444. /* Set up the DDC bus. */
  445. ddc_bus = gma_i2c_create(dev, GPIOC, "LVDSDDC_C");
  446. if (!ddc_bus) {
  447. dev_printk(KERN_ERR, dev->dev,
  448. "DDC bus registration " "failed.\n");
  449. goto err_free_lvds_priv;
  450. }
  451. ret = drm_connector_init_with_ddc(dev, connector,
  452. &cdv_intel_lvds_connector_funcs,
  453. DRM_MODE_CONNECTOR_LVDS,
  454. &ddc_bus->base);
  455. if (ret)
  456. goto err_destroy_ddc;
  457. ret = drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_LVDS);
  458. if (ret)
  459. goto err_connector_cleanup;
  460. gma_connector_attach_encoder(gma_connector, gma_encoder);
  461. gma_encoder->type = INTEL_OUTPUT_LVDS;
  462. drm_encoder_helper_add(encoder, &cdv_intel_lvds_helper_funcs);
  463. drm_connector_helper_add(connector,
  464. &cdv_intel_lvds_connector_helper_funcs);
  465. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  466. connector->interlace_allowed = false;
  467. connector->doublescan_allowed = false;
  468. /*Attach connector properties*/
  469. drm_object_attach_property(&connector->base,
  470. dev->mode_config.scaling_mode_property,
  471. DRM_MODE_SCALE_FULLSCREEN);
  472. drm_object_attach_property(&connector->base,
  473. dev_priv->backlight_property,
  474. BRIGHTNESS_MAX_LEVEL);
  475. /**
  476. * Set up I2C bus
  477. * FIXME: distroy i2c_bus when exit
  478. */
  479. gma_encoder->i2c_bus = gma_i2c_create(dev, GPIOB, "LVDSBLC_B");
  480. if (!gma_encoder->i2c_bus) {
  481. dev_printk(KERN_ERR,
  482. dev->dev, "I2C bus registration failed.\n");
  483. goto err_encoder_cleanup;
  484. }
  485. gma_encoder->i2c_bus->target_addr = 0x2C;
  486. dev_priv->lvds_i2c_bus = gma_encoder->i2c_bus;
  487. /*
  488. * LVDS discovery:
  489. * 1) check for EDID on DDC
  490. * 2) check for VBT data
  491. * 3) check to see if LVDS is already on
  492. * if none of the above, no panel
  493. * 4) make sure lid is open
  494. * if closed, act like it's not there for now
  495. */
  496. /*
  497. * Attempt to get the fixed panel mode from DDC. Assume that the
  498. * preferred mode is the right one.
  499. */
  500. mutex_lock(&dev->mode_config.mutex);
  501. psb_intel_ddc_get_modes(connector, &ddc_bus->base);
  502. list_for_each_entry(scan, &connector->probed_modes, head) {
  503. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  504. mode_dev->panel_fixed_mode =
  505. drm_mode_duplicate(dev, scan);
  506. goto out; /* FIXME: check for quirks */
  507. }
  508. }
  509. /* Failed to get EDID, what about VBT? do we need this?*/
  510. if (dev_priv->lfp_lvds_vbt_mode) {
  511. mode_dev->panel_fixed_mode =
  512. drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  513. if (mode_dev->panel_fixed_mode) {
  514. mode_dev->panel_fixed_mode->type |=
  515. DRM_MODE_TYPE_PREFERRED;
  516. goto out; /* FIXME: check for quirks */
  517. }
  518. }
  519. /*
  520. * If we didn't get EDID, try checking if the panel is already turned
  521. * on. If so, assume that whatever is currently programmed is the
  522. * correct mode.
  523. */
  524. lvds = REG_READ(LVDS);
  525. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  526. crtc = psb_intel_get_crtc_from_pipe(dev, pipe);
  527. if (crtc && (lvds & LVDS_PORT_EN)) {
  528. mode_dev->panel_fixed_mode =
  529. cdv_intel_crtc_mode_get(dev, crtc);
  530. if (mode_dev->panel_fixed_mode) {
  531. mode_dev->panel_fixed_mode->type |=
  532. DRM_MODE_TYPE_PREFERRED;
  533. goto out; /* FIXME: check for quirks */
  534. }
  535. }
  536. /* If we still don't have a mode after all that, give up. */
  537. if (!mode_dev->panel_fixed_mode) {
  538. DRM_DEBUG
  539. ("Found no modes on the lvds, ignoring the LVDS\n");
  540. goto err_unlock;
  541. }
  542. /* setup PWM */
  543. {
  544. u32 pwm;
  545. pwm = REG_READ(BLC_PWM_CTL2);
  546. if (pipe == 1)
  547. pwm |= PWM_PIPE_B;
  548. else
  549. pwm &= ~PWM_PIPE_B;
  550. pwm |= PWM_ENABLE;
  551. REG_WRITE(BLC_PWM_CTL2, pwm);
  552. }
  553. out:
  554. mutex_unlock(&dev->mode_config.mutex);
  555. return;
  556. err_unlock:
  557. mutex_unlock(&dev->mode_config.mutex);
  558. gma_i2c_destroy(gma_encoder->i2c_bus);
  559. err_encoder_cleanup:
  560. drm_encoder_cleanup(encoder);
  561. err_connector_cleanup:
  562. drm_connector_cleanup(connector);
  563. err_destroy_ddc:
  564. gma_i2c_destroy(ddc_bus);
  565. err_free_lvds_priv:
  566. kfree(lvds_priv);
  567. err_free_connector:
  568. kfree(gma_connector);
  569. err_free_encoder:
  570. kfree(gma_encoder);
  571. }