intel_crt.c 19 KB

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