intel_crt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/i2c.h>
  28. #include <linux/slab.h>
  29. #include "drmP.h"
  30. #include "drm_crtc.h"
  31. #include "drm_crtc_helper.h"
  32. #include "drm_edid.h"
  33. #include "intel_drv.h"
  34. #include "i915_drm.h"
  35. #include "i915_drv.h"
  36. /* Here's the desired hotplug mode */
  37. #define ADPA_HOTPLUG_BITS (ADPA_CRT_HOTPLUG_PERIOD_128 | \
  38. ADPA_CRT_HOTPLUG_WARMUP_10MS | \
  39. ADPA_CRT_HOTPLUG_SAMPLE_4S | \
  40. ADPA_CRT_HOTPLUG_VOLTAGE_50 | \
  41. ADPA_CRT_HOTPLUG_VOLREF_325MV | \
  42. ADPA_CRT_HOTPLUG_ENABLE)
  43. struct intel_crt {
  44. struct intel_encoder base;
  45. bool force_hotplug_required;
  46. };
  47. static struct intel_crt *intel_attached_crt(struct drm_connector *connector)
  48. {
  49. return container_of(intel_attached_encoder(connector),
  50. struct intel_crt, base);
  51. }
  52. static void pch_crt_dpms(struct drm_encoder *encoder, int mode)
  53. {
  54. struct drm_device *dev = encoder->dev;
  55. struct drm_i915_private *dev_priv = dev->dev_private;
  56. u32 temp;
  57. temp = I915_READ(PCH_ADPA);
  58. temp &= ~ADPA_DAC_ENABLE;
  59. switch (mode) {
  60. case DRM_MODE_DPMS_ON:
  61. temp |= ADPA_DAC_ENABLE;
  62. break;
  63. case DRM_MODE_DPMS_STANDBY:
  64. case DRM_MODE_DPMS_SUSPEND:
  65. case DRM_MODE_DPMS_OFF:
  66. /* Just leave port enable cleared */
  67. break;
  68. }
  69. I915_WRITE(PCH_ADPA, temp);
  70. }
  71. static void gmch_crt_dpms(struct drm_encoder *encoder, int mode)
  72. {
  73. struct drm_device *dev = encoder->dev;
  74. struct drm_i915_private *dev_priv = dev->dev_private;
  75. u32 temp;
  76. temp = I915_READ(ADPA);
  77. temp &= ~(ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
  78. temp &= ~ADPA_DAC_ENABLE;
  79. if (IS_VALLEYVIEW(dev) && mode != DRM_MODE_DPMS_ON)
  80. mode = DRM_MODE_DPMS_OFF;
  81. switch (mode) {
  82. case DRM_MODE_DPMS_ON:
  83. temp |= ADPA_DAC_ENABLE;
  84. break;
  85. case DRM_MODE_DPMS_STANDBY:
  86. temp |= ADPA_DAC_ENABLE | ADPA_HSYNC_CNTL_DISABLE;
  87. break;
  88. case DRM_MODE_DPMS_SUSPEND:
  89. temp |= ADPA_DAC_ENABLE | ADPA_VSYNC_CNTL_DISABLE;
  90. break;
  91. case DRM_MODE_DPMS_OFF:
  92. temp |= ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE;
  93. break;
  94. }
  95. I915_WRITE(ADPA, temp);
  96. }
  97. static int intel_crt_mode_valid(struct drm_connector *connector,
  98. struct drm_display_mode *mode)
  99. {
  100. struct drm_device *dev = connector->dev;
  101. int max_clock = 0;
  102. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  103. return MODE_NO_DBLESCAN;
  104. if (mode->clock < 25000)
  105. return MODE_CLOCK_LOW;
  106. if (IS_GEN2(dev))
  107. max_clock = 350000;
  108. else
  109. max_clock = 400000;
  110. if (mode->clock > max_clock)
  111. return MODE_CLOCK_HIGH;
  112. return MODE_OK;
  113. }
  114. static bool intel_crt_mode_fixup(struct drm_encoder *encoder,
  115. const struct drm_display_mode *mode,
  116. struct drm_display_mode *adjusted_mode)
  117. {
  118. return true;
  119. }
  120. static void intel_crt_mode_set(struct drm_encoder *encoder,
  121. struct drm_display_mode *mode,
  122. struct drm_display_mode *adjusted_mode)
  123. {
  124. struct drm_device *dev = encoder->dev;
  125. struct drm_crtc *crtc = encoder->crtc;
  126. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  127. struct drm_i915_private *dev_priv = dev->dev_private;
  128. int dpll_md_reg;
  129. u32 adpa, dpll_md;
  130. u32 adpa_reg;
  131. dpll_md_reg = DPLL_MD(intel_crtc->pipe);
  132. if (HAS_PCH_SPLIT(dev))
  133. adpa_reg = PCH_ADPA;
  134. else
  135. adpa_reg = ADPA;
  136. /*
  137. * Disable separate mode multiplier used when cloning SDVO to CRT
  138. * XXX this needs to be adjusted when we really are cloning
  139. */
  140. if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
  141. dpll_md = I915_READ(dpll_md_reg);
  142. I915_WRITE(dpll_md_reg,
  143. dpll_md & ~DPLL_MD_UDI_MULTIPLIER_MASK);
  144. }
  145. adpa = ADPA_HOTPLUG_BITS;
  146. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  147. adpa |= ADPA_HSYNC_ACTIVE_HIGH;
  148. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  149. adpa |= ADPA_VSYNC_ACTIVE_HIGH;
  150. /* For CPT allow 3 pipe config, for others just use A or B */
  151. if (HAS_PCH_CPT(dev))
  152. adpa |= PORT_TRANS_SEL_CPT(intel_crtc->pipe);
  153. else if (intel_crtc->pipe == 0)
  154. adpa |= ADPA_PIPE_A_SELECT;
  155. else
  156. adpa |= ADPA_PIPE_B_SELECT;
  157. if (!HAS_PCH_SPLIT(dev))
  158. I915_WRITE(BCLRPAT(intel_crtc->pipe), 0);
  159. I915_WRITE(adpa_reg, adpa);
  160. }
  161. static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector)
  162. {
  163. struct drm_device *dev = connector->dev;
  164. struct intel_crt *crt = intel_attached_crt(connector);
  165. struct drm_i915_private *dev_priv = dev->dev_private;
  166. u32 adpa;
  167. bool ret;
  168. /* The first time through, trigger an explicit detection cycle */
  169. if (crt->force_hotplug_required) {
  170. bool turn_off_dac = HAS_PCH_SPLIT(dev);
  171. u32 save_adpa;
  172. crt->force_hotplug_required = 0;
  173. save_adpa = adpa = I915_READ(PCH_ADPA);
  174. DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa);
  175. adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
  176. if (turn_off_dac)
  177. adpa &= ~ADPA_DAC_ENABLE;
  178. I915_WRITE(PCH_ADPA, adpa);
  179. if (wait_for((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
  180. 1000))
  181. DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
  182. if (turn_off_dac) {
  183. I915_WRITE(PCH_ADPA, save_adpa);
  184. POSTING_READ(PCH_ADPA);
  185. }
  186. }
  187. /* Check the status to see if both blue and green are on now */
  188. adpa = I915_READ(PCH_ADPA);
  189. if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
  190. ret = true;
  191. else
  192. ret = false;
  193. DRM_DEBUG_KMS("ironlake hotplug adpa=0x%x, result %d\n", adpa, ret);
  194. return ret;
  195. }
  196. static bool valleyview_crt_detect_hotplug(struct drm_connector *connector)
  197. {
  198. struct drm_device *dev = connector->dev;
  199. struct drm_i915_private *dev_priv = dev->dev_private;
  200. u32 adpa;
  201. bool ret;
  202. u32 save_adpa;
  203. save_adpa = adpa = I915_READ(ADPA);
  204. DRM_DEBUG_KMS("trigger hotplug detect cycle: adpa=0x%x\n", adpa);
  205. adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
  206. I915_WRITE(ADPA, adpa);
  207. if (wait_for((I915_READ(ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
  208. 1000)) {
  209. DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
  210. I915_WRITE(ADPA, save_adpa);
  211. }
  212. /* Check the status to see if both blue and green are on now */
  213. adpa = I915_READ(ADPA);
  214. if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
  215. ret = true;
  216. else
  217. ret = false;
  218. DRM_DEBUG_KMS("valleyview hotplug adpa=0x%x, result %d\n", adpa, ret);
  219. /* FIXME: debug force function and remove */
  220. ret = true;
  221. return ret;
  222. }
  223. /**
  224. * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect CRT presence.
  225. *
  226. * Not for i915G/i915GM
  227. *
  228. * \return true if CRT is connected.
  229. * \return false if CRT is disconnected.
  230. */
  231. static bool intel_crt_detect_hotplug(struct drm_connector *connector)
  232. {
  233. struct drm_device *dev = connector->dev;
  234. struct drm_i915_private *dev_priv = dev->dev_private;
  235. u32 hotplug_en, orig, stat;
  236. bool ret = false;
  237. int i, tries = 0;
  238. if (HAS_PCH_SPLIT(dev))
  239. return intel_ironlake_crt_detect_hotplug(connector);
  240. if (IS_VALLEYVIEW(dev))
  241. return valleyview_crt_detect_hotplug(connector);
  242. /*
  243. * On 4 series desktop, CRT detect sequence need to be done twice
  244. * to get a reliable result.
  245. */
  246. if (IS_G4X(dev) && !IS_GM45(dev))
  247. tries = 2;
  248. else
  249. tries = 1;
  250. hotplug_en = orig = I915_READ(PORT_HOTPLUG_EN);
  251. hotplug_en |= CRT_HOTPLUG_FORCE_DETECT;
  252. for (i = 0; i < tries ; i++) {
  253. /* turn on the FORCE_DETECT */
  254. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  255. /* wait for FORCE_DETECT to go off */
  256. if (wait_for((I915_READ(PORT_HOTPLUG_EN) &
  257. CRT_HOTPLUG_FORCE_DETECT) == 0,
  258. 1000))
  259. DRM_DEBUG_KMS("timed out waiting for FORCE_DETECT to go off");
  260. }
  261. stat = I915_READ(PORT_HOTPLUG_STAT);
  262. if ((stat & CRT_HOTPLUG_MONITOR_MASK) != CRT_HOTPLUG_MONITOR_NONE)
  263. ret = true;
  264. /* clear the interrupt we just generated, if any */
  265. I915_WRITE(PORT_HOTPLUG_STAT, CRT_HOTPLUG_INT_STATUS);
  266. /* and put the bits back */
  267. I915_WRITE(PORT_HOTPLUG_EN, orig);
  268. return ret;
  269. }
  270. static struct edid *intel_crt_get_edid(struct drm_connector *connector,
  271. struct i2c_adapter *i2c)
  272. {
  273. struct edid *edid;
  274. edid = drm_get_edid(connector, i2c);
  275. if (!edid && !intel_gmbus_is_forced_bit(i2c)) {
  276. DRM_DEBUG_KMS("CRT GMBUS EDID read failed, retry using GPIO bit-banging\n");
  277. intel_gmbus_force_bit(i2c, true);
  278. edid = drm_get_edid(connector, i2c);
  279. intel_gmbus_force_bit(i2c, false);
  280. }
  281. return edid;
  282. }
  283. /* local version of intel_ddc_get_modes() to use intel_crt_get_edid() */
  284. static int intel_crt_ddc_get_modes(struct drm_connector *connector,
  285. struct i2c_adapter *adapter)
  286. {
  287. struct edid *edid;
  288. edid = intel_crt_get_edid(connector, adapter);
  289. if (!edid)
  290. return 0;
  291. return intel_connector_update_modes(connector, edid);
  292. }
  293. static bool intel_crt_detect_ddc(struct drm_connector *connector)
  294. {
  295. struct intel_crt *crt = intel_attached_crt(connector);
  296. struct drm_i915_private *dev_priv = crt->base.base.dev->dev_private;
  297. struct edid *edid;
  298. struct i2c_adapter *i2c;
  299. BUG_ON(crt->base.type != INTEL_OUTPUT_ANALOG);
  300. i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->crt_ddc_pin);
  301. edid = intel_crt_get_edid(connector, i2c);
  302. if (edid) {
  303. bool is_digital = edid->input & DRM_EDID_INPUT_DIGITAL;
  304. /*
  305. * This may be a DVI-I connector with a shared DDC
  306. * link between analog and digital outputs, so we
  307. * have to check the EDID input spec of the attached device.
  308. */
  309. if (!is_digital) {
  310. DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n");
  311. return true;
  312. }
  313. DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [EDID reports a digital panel]\n");
  314. } else {
  315. DRM_DEBUG_KMS("CRT not detected via DDC:0x50 [no valid EDID found]\n");
  316. }
  317. kfree(edid);
  318. return false;
  319. }
  320. static enum drm_connector_status
  321. intel_crt_load_detect(struct intel_crt *crt)
  322. {
  323. struct drm_device *dev = crt->base.base.dev;
  324. struct drm_i915_private *dev_priv = dev->dev_private;
  325. uint32_t pipe = to_intel_crtc(crt->base.base.crtc)->pipe;
  326. uint32_t save_bclrpat;
  327. uint32_t save_vtotal;
  328. uint32_t vtotal, vactive;
  329. uint32_t vsample;
  330. uint32_t vblank, vblank_start, vblank_end;
  331. uint32_t dsl;
  332. uint32_t bclrpat_reg;
  333. uint32_t vtotal_reg;
  334. uint32_t vblank_reg;
  335. uint32_t vsync_reg;
  336. uint32_t pipeconf_reg;
  337. uint32_t pipe_dsl_reg;
  338. uint8_t st00;
  339. enum drm_connector_status status;
  340. DRM_DEBUG_KMS("starting load-detect on CRT\n");
  341. bclrpat_reg = BCLRPAT(pipe);
  342. vtotal_reg = VTOTAL(pipe);
  343. vblank_reg = VBLANK(pipe);
  344. vsync_reg = VSYNC(pipe);
  345. pipeconf_reg = PIPECONF(pipe);
  346. pipe_dsl_reg = PIPEDSL(pipe);
  347. save_bclrpat = I915_READ(bclrpat_reg);
  348. save_vtotal = I915_READ(vtotal_reg);
  349. vblank = I915_READ(vblank_reg);
  350. vtotal = ((save_vtotal >> 16) & 0xfff) + 1;
  351. vactive = (save_vtotal & 0x7ff) + 1;
  352. vblank_start = (vblank & 0xfff) + 1;
  353. vblank_end = ((vblank >> 16) & 0xfff) + 1;
  354. /* Set the border color to purple. */
  355. I915_WRITE(bclrpat_reg, 0x500050);
  356. if (!IS_GEN2(dev)) {
  357. uint32_t pipeconf = I915_READ(pipeconf_reg);
  358. I915_WRITE(pipeconf_reg, pipeconf | PIPECONF_FORCE_BORDER);
  359. POSTING_READ(pipeconf_reg);
  360. /* Wait for next Vblank to substitue
  361. * border color for Color info */
  362. intel_wait_for_vblank(dev, pipe);
  363. st00 = I915_READ8(VGA_MSR_WRITE);
  364. status = ((st00 & (1 << 4)) != 0) ?
  365. connector_status_connected :
  366. connector_status_disconnected;
  367. I915_WRITE(pipeconf_reg, pipeconf);
  368. } else {
  369. bool restore_vblank = false;
  370. int count, detect;
  371. /*
  372. * If there isn't any border, add some.
  373. * Yes, this will flicker
  374. */
  375. if (vblank_start <= vactive && vblank_end >= vtotal) {
  376. uint32_t vsync = I915_READ(vsync_reg);
  377. uint32_t vsync_start = (vsync & 0xffff) + 1;
  378. vblank_start = vsync_start;
  379. I915_WRITE(vblank_reg,
  380. (vblank_start - 1) |
  381. ((vblank_end - 1) << 16));
  382. restore_vblank = true;
  383. }
  384. /* sample in the vertical border, selecting the larger one */
  385. if (vblank_start - vactive >= vtotal - vblank_end)
  386. vsample = (vblank_start + vactive) >> 1;
  387. else
  388. vsample = (vtotal + vblank_end) >> 1;
  389. /*
  390. * Wait for the border to be displayed
  391. */
  392. while (I915_READ(pipe_dsl_reg) >= vactive)
  393. ;
  394. while ((dsl = I915_READ(pipe_dsl_reg)) <= vsample)
  395. ;
  396. /*
  397. * Watch ST00 for an entire scanline
  398. */
  399. detect = 0;
  400. count = 0;
  401. do {
  402. count++;
  403. /* Read the ST00 VGA status register */
  404. st00 = I915_READ8(VGA_MSR_WRITE);
  405. if (st00 & (1 << 4))
  406. detect++;
  407. } while ((I915_READ(pipe_dsl_reg) == dsl));
  408. /* restore vblank if necessary */
  409. if (restore_vblank)
  410. I915_WRITE(vblank_reg, vblank);
  411. /*
  412. * If more than 3/4 of the scanline detected a monitor,
  413. * then it is assumed to be present. This works even on i830,
  414. * where there isn't any way to force the border color across
  415. * the screen
  416. */
  417. status = detect * 4 > count * 3 ?
  418. connector_status_connected :
  419. connector_status_disconnected;
  420. }
  421. /* Restore previous settings */
  422. I915_WRITE(bclrpat_reg, save_bclrpat);
  423. return status;
  424. }
  425. static enum drm_connector_status
  426. intel_crt_detect(struct drm_connector *connector, bool force)
  427. {
  428. struct drm_device *dev = connector->dev;
  429. struct intel_crt *crt = intel_attached_crt(connector);
  430. enum drm_connector_status status;
  431. struct intel_load_detect_pipe tmp;
  432. if (I915_HAS_HOTPLUG(dev)) {
  433. /* We can not rely on the HPD pin always being correctly wired
  434. * up, for example many KVM do not pass it through, and so
  435. * only trust an assertion that the monitor is connected.
  436. */
  437. if (intel_crt_detect_hotplug(connector)) {
  438. DRM_DEBUG_KMS("CRT detected via hotplug\n");
  439. return connector_status_connected;
  440. } else
  441. DRM_DEBUG_KMS("CRT not detected via hotplug\n");
  442. }
  443. if (intel_crt_detect_ddc(connector))
  444. return connector_status_connected;
  445. /* Load detection is broken on HPD capable machines. Whoever wants a
  446. * broken monitor (without edid) to work behind a broken kvm (that fails
  447. * to have the right resistors for HP detection) needs to fix this up.
  448. * For now just bail out. */
  449. if (I915_HAS_HOTPLUG(dev))
  450. return connector_status_disconnected;
  451. if (!force)
  452. return connector->status;
  453. /* for pre-945g platforms use load detect */
  454. if (intel_get_load_detect_pipe(&crt->base, connector, NULL,
  455. &tmp)) {
  456. if (intel_crt_detect_ddc(connector))
  457. status = connector_status_connected;
  458. else
  459. status = intel_crt_load_detect(crt);
  460. intel_release_load_detect_pipe(&crt->base, connector,
  461. &tmp);
  462. } else
  463. status = connector_status_unknown;
  464. return status;
  465. }
  466. static void intel_crt_destroy(struct drm_connector *connector)
  467. {
  468. drm_sysfs_connector_remove(connector);
  469. drm_connector_cleanup(connector);
  470. kfree(connector);
  471. }
  472. static int intel_crt_get_modes(struct drm_connector *connector)
  473. {
  474. struct drm_device *dev = connector->dev;
  475. struct drm_i915_private *dev_priv = dev->dev_private;
  476. int ret;
  477. struct i2c_adapter *i2c;
  478. i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->crt_ddc_pin);
  479. ret = intel_crt_ddc_get_modes(connector, i2c);
  480. if (ret || !IS_G4X(dev))
  481. return ret;
  482. /* Try to probe digital port for output in DVI-I -> VGA mode. */
  483. i2c = intel_gmbus_get_adapter(dev_priv, GMBUS_PORT_DPB);
  484. return intel_crt_ddc_get_modes(connector, i2c);
  485. }
  486. static int intel_crt_set_property(struct drm_connector *connector,
  487. struct drm_property *property,
  488. uint64_t value)
  489. {
  490. return 0;
  491. }
  492. static void intel_crt_reset(struct drm_connector *connector)
  493. {
  494. struct drm_device *dev = connector->dev;
  495. struct intel_crt *crt = intel_attached_crt(connector);
  496. if (HAS_PCH_SPLIT(dev))
  497. crt->force_hotplug_required = 1;
  498. }
  499. /*
  500. * Routines for controlling stuff on the analog port
  501. */
  502. static const struct drm_encoder_helper_funcs pch_encoder_funcs = {
  503. .mode_fixup = intel_crt_mode_fixup,
  504. .prepare = intel_encoder_prepare,
  505. .commit = intel_encoder_commit,
  506. .mode_set = intel_crt_mode_set,
  507. .dpms = pch_crt_dpms,
  508. };
  509. static const struct drm_encoder_helper_funcs gmch_encoder_funcs = {
  510. .mode_fixup = intel_crt_mode_fixup,
  511. .prepare = intel_encoder_prepare,
  512. .commit = intel_encoder_commit,
  513. .mode_set = intel_crt_mode_set,
  514. .dpms = gmch_crt_dpms,
  515. };
  516. static const struct drm_connector_funcs intel_crt_connector_funcs = {
  517. .reset = intel_crt_reset,
  518. .dpms = drm_helper_connector_dpms,
  519. .detect = intel_crt_detect,
  520. .fill_modes = drm_helper_probe_single_connector_modes,
  521. .destroy = intel_crt_destroy,
  522. .set_property = intel_crt_set_property,
  523. };
  524. static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = {
  525. .mode_valid = intel_crt_mode_valid,
  526. .get_modes = intel_crt_get_modes,
  527. .best_encoder = intel_best_encoder,
  528. };
  529. static const struct drm_encoder_funcs intel_crt_enc_funcs = {
  530. .destroy = intel_encoder_destroy,
  531. };
  532. static int __init intel_no_crt_dmi_callback(const struct dmi_system_id *id)
  533. {
  534. DRM_INFO("Skipping CRT initialization for %s\n", id->ident);
  535. return 1;
  536. }
  537. static const struct dmi_system_id intel_no_crt[] = {
  538. {
  539. .callback = intel_no_crt_dmi_callback,
  540. .ident = "ACER ZGB",
  541. .matches = {
  542. DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
  543. DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
  544. },
  545. },
  546. { }
  547. };
  548. void intel_crt_init(struct drm_device *dev)
  549. {
  550. struct drm_connector *connector;
  551. struct intel_crt *crt;
  552. struct intel_connector *intel_connector;
  553. struct drm_i915_private *dev_priv = dev->dev_private;
  554. const struct drm_encoder_helper_funcs *encoder_helper_funcs;
  555. /* Skip machines without VGA that falsely report hotplug events */
  556. if (dmi_check_system(intel_no_crt))
  557. return;
  558. crt = kzalloc(sizeof(struct intel_crt), GFP_KERNEL);
  559. if (!crt)
  560. return;
  561. intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
  562. if (!intel_connector) {
  563. kfree(crt);
  564. return;
  565. }
  566. connector = &intel_connector->base;
  567. drm_connector_init(dev, &intel_connector->base,
  568. &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
  569. drm_encoder_init(dev, &crt->base.base, &intel_crt_enc_funcs,
  570. DRM_MODE_ENCODER_DAC);
  571. intel_connector_attach_encoder(intel_connector, &crt->base);
  572. crt->base.type = INTEL_OUTPUT_ANALOG;
  573. crt->base.clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT |
  574. 1 << INTEL_ANALOG_CLONE_BIT |
  575. 1 << INTEL_SDVO_LVDS_CLONE_BIT);
  576. if (IS_HASWELL(dev))
  577. crt->base.crtc_mask = (1 << 0);
  578. else
  579. crt->base.crtc_mask = (1 << 0) | (1 << 1);
  580. if (IS_GEN2(dev))
  581. connector->interlace_allowed = 0;
  582. else
  583. connector->interlace_allowed = 1;
  584. connector->doublescan_allowed = 0;
  585. if (HAS_PCH_SPLIT(dev))
  586. encoder_helper_funcs = &pch_encoder_funcs;
  587. else
  588. encoder_helper_funcs = &gmch_encoder_funcs;
  589. drm_encoder_helper_add(&crt->base.base, encoder_helper_funcs);
  590. drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
  591. drm_sysfs_connector_add(connector);
  592. if (I915_HAS_HOTPLUG(dev))
  593. connector->polled = DRM_CONNECTOR_POLL_HPD;
  594. else
  595. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  596. /*
  597. * Configure the automatic hotplug detection stuff
  598. */
  599. crt->force_hotplug_required = 0;
  600. if (HAS_PCH_SPLIT(dev)) {
  601. u32 adpa;
  602. adpa = I915_READ(PCH_ADPA);
  603. adpa &= ~ADPA_CRT_HOTPLUG_MASK;
  604. adpa |= ADPA_HOTPLUG_BITS;
  605. I915_WRITE(PCH_ADPA, adpa);
  606. POSTING_READ(PCH_ADPA);
  607. DRM_DEBUG_KMS("pch crt adpa set to 0x%x\n", adpa);
  608. crt->force_hotplug_required = 1;
  609. }
  610. dev_priv->hotplug_supported_mask |= CRT_HOTPLUG_INT_STATUS;
  611. }