intel_crt.c 21 KB

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