radeon_dp_mst.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. #include <drm/drmP.h>
  2. #include <drm/drm_dp_mst_helper.h>
  3. #include <drm/drm_fb_helper.h>
  4. #include "radeon.h"
  5. #include "atom.h"
  6. #include "ni_reg.h"
  7. static struct radeon_encoder *radeon_dp_create_fake_mst_encoder(struct radeon_connector *connector);
  8. static int radeon_atom_set_enc_offset(int id)
  9. {
  10. static const int offsets[] = { EVERGREEN_CRTC0_REGISTER_OFFSET,
  11. EVERGREEN_CRTC1_REGISTER_OFFSET,
  12. EVERGREEN_CRTC2_REGISTER_OFFSET,
  13. EVERGREEN_CRTC3_REGISTER_OFFSET,
  14. EVERGREEN_CRTC4_REGISTER_OFFSET,
  15. EVERGREEN_CRTC5_REGISTER_OFFSET,
  16. 0x13830 - 0x7030 };
  17. return offsets[id];
  18. }
  19. static int radeon_dp_mst_set_be_cntl(struct radeon_encoder *primary,
  20. struct radeon_encoder_mst *mst_enc,
  21. enum radeon_hpd_id hpd, bool enable)
  22. {
  23. struct drm_device *dev = primary->base.dev;
  24. struct radeon_device *rdev = dev->dev_private;
  25. uint32_t reg;
  26. int retries = 0;
  27. uint32_t temp;
  28. reg = RREG32(NI_DIG_BE_CNTL + primary->offset);
  29. /* set MST mode */
  30. reg &= ~NI_DIG_FE_DIG_MODE(7);
  31. reg |= NI_DIG_FE_DIG_MODE(NI_DIG_MODE_DP_MST);
  32. if (enable)
  33. reg |= NI_DIG_FE_SOURCE_SELECT(1 << mst_enc->fe);
  34. else
  35. reg &= ~NI_DIG_FE_SOURCE_SELECT(1 << mst_enc->fe);
  36. reg |= NI_DIG_HPD_SELECT(hpd);
  37. DRM_DEBUG_KMS("writing 0x%08x 0x%08x\n", NI_DIG_BE_CNTL + primary->offset, reg);
  38. WREG32(NI_DIG_BE_CNTL + primary->offset, reg);
  39. if (enable) {
  40. uint32_t offset = radeon_atom_set_enc_offset(mst_enc->fe);
  41. do {
  42. temp = RREG32(NI_DIG_FE_CNTL + offset);
  43. } while ((temp & NI_DIG_SYMCLK_FE_ON) && retries++ < 10000);
  44. if (retries == 10000)
  45. DRM_ERROR("timed out waiting for FE %d %d\n", primary->offset, mst_enc->fe);
  46. }
  47. return 0;
  48. }
  49. static int radeon_dp_mst_set_stream_attrib(struct radeon_encoder *primary,
  50. int stream_number,
  51. int fe,
  52. int slots)
  53. {
  54. struct drm_device *dev = primary->base.dev;
  55. struct radeon_device *rdev = dev->dev_private;
  56. u32 temp, val;
  57. int retries = 0;
  58. int satreg, satidx;
  59. satreg = stream_number >> 1;
  60. satidx = stream_number & 1;
  61. temp = RREG32(NI_DP_MSE_SAT0 + satreg + primary->offset);
  62. val = NI_DP_MSE_SAT_SLOT_COUNT0(slots) | NI_DP_MSE_SAT_SRC0(fe);
  63. val <<= (16 * satidx);
  64. temp &= ~(0xffff << (16 * satidx));
  65. temp |= val;
  66. DRM_DEBUG_KMS("writing 0x%08x 0x%08x\n", NI_DP_MSE_SAT0 + satreg + primary->offset, temp);
  67. WREG32(NI_DP_MSE_SAT0 + satreg + primary->offset, temp);
  68. WREG32(NI_DP_MSE_SAT_UPDATE + primary->offset, 1);
  69. do {
  70. temp = RREG32(NI_DP_MSE_SAT_UPDATE + primary->offset);
  71. } while ((temp & 0x1) && retries++ < 10000);
  72. if (retries == 10000)
  73. DRM_ERROR("timed out waitin for SAT update %d\n", primary->offset);
  74. /* MTP 16 ? */
  75. return 0;
  76. }
  77. static int radeon_dp_mst_update_stream_attribs(struct radeon_connector *mst_conn,
  78. struct radeon_encoder *primary)
  79. {
  80. struct drm_device *dev = mst_conn->base.dev;
  81. struct stream_attribs new_attribs[6];
  82. int i;
  83. int idx = 0;
  84. struct radeon_connector *radeon_connector;
  85. struct drm_connector *connector;
  86. memset(new_attribs, 0, sizeof(new_attribs));
  87. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  88. struct radeon_encoder *subenc;
  89. struct radeon_encoder_mst *mst_enc;
  90. radeon_connector = to_radeon_connector(connector);
  91. if (!radeon_connector->is_mst_connector)
  92. continue;
  93. if (radeon_connector->mst_port != mst_conn)
  94. continue;
  95. subenc = radeon_connector->mst_encoder;
  96. mst_enc = subenc->enc_priv;
  97. if (!mst_enc->enc_active)
  98. continue;
  99. new_attribs[idx].fe = mst_enc->fe;
  100. new_attribs[idx].slots = drm_dp_mst_get_vcpi_slots(&mst_conn->mst_mgr, mst_enc->port);
  101. idx++;
  102. }
  103. for (i = 0; i < idx; i++) {
  104. if (new_attribs[i].fe != mst_conn->cur_stream_attribs[i].fe ||
  105. new_attribs[i].slots != mst_conn->cur_stream_attribs[i].slots) {
  106. radeon_dp_mst_set_stream_attrib(primary, i, new_attribs[i].fe, new_attribs[i].slots);
  107. mst_conn->cur_stream_attribs[i].fe = new_attribs[i].fe;
  108. mst_conn->cur_stream_attribs[i].slots = new_attribs[i].slots;
  109. }
  110. }
  111. for (i = idx; i < mst_conn->enabled_attribs; i++) {
  112. radeon_dp_mst_set_stream_attrib(primary, i, 0, 0);
  113. mst_conn->cur_stream_attribs[i].fe = 0;
  114. mst_conn->cur_stream_attribs[i].slots = 0;
  115. }
  116. mst_conn->enabled_attribs = idx;
  117. return 0;
  118. }
  119. static int radeon_dp_mst_set_vcp_size(struct radeon_encoder *mst, uint32_t x, uint32_t y)
  120. {
  121. struct drm_device *dev = mst->base.dev;
  122. struct radeon_device *rdev = dev->dev_private;
  123. struct radeon_encoder_mst *mst_enc = mst->enc_priv;
  124. uint32_t val, temp;
  125. uint32_t offset = radeon_atom_set_enc_offset(mst_enc->fe);
  126. int retries = 0;
  127. val = NI_DP_MSE_RATE_X(x) | NI_DP_MSE_RATE_Y(y);
  128. WREG32(NI_DP_MSE_RATE_CNTL + offset, val);
  129. do {
  130. temp = RREG32(NI_DP_MSE_RATE_UPDATE + offset);
  131. } while ((temp & 0x1) && (retries++ < 10000));
  132. if (retries >= 10000)
  133. DRM_ERROR("timed out wait for rate cntl %d\n", mst_enc->fe);
  134. return 0;
  135. }
  136. static int radeon_dp_mst_get_ddc_modes(struct drm_connector *connector)
  137. {
  138. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  139. struct radeon_connector *master = radeon_connector->mst_port;
  140. struct edid *edid;
  141. int ret = 0;
  142. edid = drm_dp_mst_get_edid(connector, &master->mst_mgr, radeon_connector->port);
  143. radeon_connector->edid = edid;
  144. DRM_DEBUG_KMS("edid retrieved %p\n", edid);
  145. if (radeon_connector->edid) {
  146. drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid);
  147. ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid);
  148. drm_edid_to_eld(&radeon_connector->base, radeon_connector->edid);
  149. return ret;
  150. }
  151. drm_mode_connector_update_edid_property(&radeon_connector->base, NULL);
  152. return ret;
  153. }
  154. static int radeon_dp_mst_get_modes(struct drm_connector *connector)
  155. {
  156. return radeon_dp_mst_get_ddc_modes(connector);
  157. }
  158. static enum drm_mode_status
  159. radeon_dp_mst_mode_valid(struct drm_connector *connector,
  160. struct drm_display_mode *mode)
  161. {
  162. /* TODO - validate mode against available PBN for link */
  163. if (mode->clock < 10000)
  164. return MODE_CLOCK_LOW;
  165. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  166. return MODE_H_ILLEGAL;
  167. return MODE_OK;
  168. }
  169. struct drm_encoder *radeon_mst_best_encoder(struct drm_connector *connector)
  170. {
  171. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  172. return &radeon_connector->mst_encoder->base;
  173. }
  174. static const struct drm_connector_helper_funcs radeon_dp_mst_connector_helper_funcs = {
  175. .get_modes = radeon_dp_mst_get_modes,
  176. .mode_valid = radeon_dp_mst_mode_valid,
  177. .best_encoder = radeon_mst_best_encoder,
  178. };
  179. static enum drm_connector_status
  180. radeon_dp_mst_detect(struct drm_connector *connector, bool force)
  181. {
  182. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  183. struct radeon_connector *master = radeon_connector->mst_port;
  184. return drm_dp_mst_detect_port(connector, &master->mst_mgr, radeon_connector->port);
  185. }
  186. static void
  187. radeon_dp_mst_connector_destroy(struct drm_connector *connector)
  188. {
  189. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  190. struct radeon_encoder *radeon_encoder = radeon_connector->mst_encoder;
  191. drm_encoder_cleanup(&radeon_encoder->base);
  192. kfree(radeon_encoder);
  193. drm_connector_cleanup(connector);
  194. kfree(radeon_connector);
  195. }
  196. static int radeon_connector_dpms(struct drm_connector *connector, int mode)
  197. {
  198. DRM_DEBUG_KMS("\n");
  199. return 0;
  200. }
  201. static const struct drm_connector_funcs radeon_dp_mst_connector_funcs = {
  202. .dpms = radeon_connector_dpms,
  203. .detect = radeon_dp_mst_detect,
  204. .fill_modes = drm_helper_probe_single_connector_modes,
  205. .destroy = radeon_dp_mst_connector_destroy,
  206. };
  207. static struct drm_connector *radeon_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
  208. struct drm_dp_mst_port *port,
  209. const char *pathprop)
  210. {
  211. struct radeon_connector *master = container_of(mgr, struct radeon_connector, mst_mgr);
  212. struct drm_device *dev = master->base.dev;
  213. struct radeon_connector *radeon_connector;
  214. struct drm_connector *connector;
  215. radeon_connector = kzalloc(sizeof(*radeon_connector), GFP_KERNEL);
  216. if (!radeon_connector)
  217. return NULL;
  218. radeon_connector->is_mst_connector = true;
  219. connector = &radeon_connector->base;
  220. radeon_connector->port = port;
  221. radeon_connector->mst_port = master;
  222. DRM_DEBUG_KMS("\n");
  223. drm_connector_init(dev, connector, &radeon_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
  224. drm_connector_helper_add(connector, &radeon_dp_mst_connector_helper_funcs);
  225. radeon_connector->mst_encoder = radeon_dp_create_fake_mst_encoder(master);
  226. drm_object_attach_property(&connector->base, dev->mode_config.path_property, 0);
  227. drm_object_attach_property(&connector->base, dev->mode_config.tile_property, 0);
  228. drm_mode_connector_set_path_property(connector, pathprop);
  229. return connector;
  230. }
  231. static void radeon_dp_register_mst_connector(struct drm_connector *connector)
  232. {
  233. struct drm_device *dev = connector->dev;
  234. struct radeon_device *rdev = dev->dev_private;
  235. drm_modeset_lock_all(dev);
  236. radeon_fb_add_connector(rdev, connector);
  237. drm_modeset_unlock_all(dev);
  238. drm_connector_register(connector);
  239. }
  240. static void radeon_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
  241. struct drm_connector *connector)
  242. {
  243. struct radeon_connector *master = container_of(mgr, struct radeon_connector, mst_mgr);
  244. struct drm_device *dev = master->base.dev;
  245. struct radeon_device *rdev = dev->dev_private;
  246. drm_connector_unregister(connector);
  247. /* need to nuke the connector */
  248. drm_modeset_lock_all(dev);
  249. /* dpms off */
  250. radeon_fb_remove_connector(rdev, connector);
  251. drm_connector_cleanup(connector);
  252. drm_modeset_unlock_all(dev);
  253. kfree(connector);
  254. DRM_DEBUG_KMS("\n");
  255. }
  256. static void radeon_dp_mst_hotplug(struct drm_dp_mst_topology_mgr *mgr)
  257. {
  258. struct radeon_connector *master = container_of(mgr, struct radeon_connector, mst_mgr);
  259. struct drm_device *dev = master->base.dev;
  260. drm_kms_helper_hotplug_event(dev);
  261. }
  262. struct drm_dp_mst_topology_cbs mst_cbs = {
  263. .add_connector = radeon_dp_add_mst_connector,
  264. .register_connector = radeon_dp_register_mst_connector,
  265. .destroy_connector = radeon_dp_destroy_mst_connector,
  266. .hotplug = radeon_dp_mst_hotplug,
  267. };
  268. struct radeon_connector *radeon_mst_find_connector(struct drm_encoder *encoder)
  269. {
  270. struct drm_device *dev = encoder->dev;
  271. struct drm_connector *connector;
  272. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  273. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  274. if (!connector->encoder)
  275. continue;
  276. if (!radeon_connector->is_mst_connector)
  277. continue;
  278. DRM_DEBUG_KMS("checking %p vs %p\n", connector->encoder, encoder);
  279. if (connector->encoder == encoder)
  280. return radeon_connector;
  281. }
  282. return NULL;
  283. }
  284. void radeon_dp_mst_prepare_pll(struct drm_crtc *crtc, struct drm_display_mode *mode)
  285. {
  286. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  287. struct drm_device *dev = crtc->dev;
  288. struct radeon_device *rdev = dev->dev_private;
  289. struct radeon_encoder *radeon_encoder = to_radeon_encoder(radeon_crtc->encoder);
  290. struct radeon_encoder_mst *mst_enc = radeon_encoder->enc_priv;
  291. struct radeon_connector *radeon_connector = radeon_mst_find_connector(&radeon_encoder->base);
  292. int dp_clock;
  293. struct radeon_connector_atom_dig *dig_connector = mst_enc->connector->con_priv;
  294. if (radeon_connector) {
  295. radeon_connector->pixelclock_for_modeset = mode->clock;
  296. if (radeon_connector->base.display_info.bpc)
  297. radeon_crtc->bpc = radeon_connector->base.display_info.bpc;
  298. else
  299. radeon_crtc->bpc = 8;
  300. }
  301. DRM_DEBUG_KMS("dp_clock %p %d\n", dig_connector, dig_connector->dp_clock);
  302. dp_clock = dig_connector->dp_clock;
  303. radeon_crtc->ss_enabled =
  304. radeon_atombios_get_asic_ss_info(rdev, &radeon_crtc->ss,
  305. ASIC_INTERNAL_SS_ON_DP,
  306. dp_clock);
  307. }
  308. static void
  309. radeon_mst_encoder_dpms(struct drm_encoder *encoder, int mode)
  310. {
  311. struct drm_device *dev = encoder->dev;
  312. struct radeon_device *rdev = dev->dev_private;
  313. struct radeon_encoder *radeon_encoder, *primary;
  314. struct radeon_encoder_mst *mst_enc;
  315. struct radeon_encoder_atom_dig *dig_enc;
  316. struct radeon_connector *radeon_connector;
  317. struct drm_crtc *crtc;
  318. struct radeon_crtc *radeon_crtc;
  319. int ret, slots;
  320. if (!ASIC_IS_DCE5(rdev)) {
  321. DRM_ERROR("got mst dpms on non-DCE5\n");
  322. return;
  323. }
  324. radeon_connector = radeon_mst_find_connector(encoder);
  325. if (!radeon_connector)
  326. return;
  327. radeon_encoder = to_radeon_encoder(encoder);
  328. mst_enc = radeon_encoder->enc_priv;
  329. primary = mst_enc->primary;
  330. dig_enc = primary->enc_priv;
  331. crtc = encoder->crtc;
  332. DRM_DEBUG_KMS("got connector %d\n", dig_enc->active_mst_links);
  333. switch (mode) {
  334. case DRM_MODE_DPMS_ON:
  335. dig_enc->active_mst_links++;
  336. radeon_crtc = to_radeon_crtc(crtc);
  337. if (dig_enc->active_mst_links == 1) {
  338. mst_enc->fe = dig_enc->dig_encoder;
  339. mst_enc->fe_from_be = true;
  340. atombios_set_mst_encoder_crtc_source(encoder, mst_enc->fe);
  341. atombios_dig_encoder_setup(&primary->base, ATOM_ENCODER_CMD_SETUP, 0);
  342. atombios_dig_transmitter_setup2(&primary->base, ATOM_TRANSMITTER_ACTION_ENABLE,
  343. 0, 0, dig_enc->dig_encoder);
  344. if (radeon_dp_needs_link_train(mst_enc->connector) ||
  345. dig_enc->active_mst_links == 1) {
  346. radeon_dp_link_train(&primary->base, &mst_enc->connector->base);
  347. }
  348. } else {
  349. mst_enc->fe = radeon_atom_pick_dig_encoder(encoder, radeon_crtc->crtc_id);
  350. if (mst_enc->fe == -1)
  351. DRM_ERROR("failed to get frontend for dig encoder\n");
  352. mst_enc->fe_from_be = false;
  353. atombios_set_mst_encoder_crtc_source(encoder, mst_enc->fe);
  354. }
  355. DRM_DEBUG_KMS("dig encoder is %d %d %d\n", dig_enc->dig_encoder,
  356. dig_enc->linkb, radeon_crtc->crtc_id);
  357. ret = drm_dp_mst_allocate_vcpi(&radeon_connector->mst_port->mst_mgr,
  358. radeon_connector->port,
  359. mst_enc->pbn, &slots);
  360. ret = drm_dp_update_payload_part1(&radeon_connector->mst_port->mst_mgr);
  361. radeon_dp_mst_set_be_cntl(primary, mst_enc,
  362. radeon_connector->mst_port->hpd.hpd, true);
  363. mst_enc->enc_active = true;
  364. radeon_dp_mst_update_stream_attribs(radeon_connector->mst_port, primary);
  365. radeon_dp_mst_set_vcp_size(radeon_encoder, slots, 0);
  366. atombios_dig_encoder_setup2(&primary->base, ATOM_ENCODER_CMD_DP_VIDEO_ON, 0,
  367. mst_enc->fe);
  368. ret = drm_dp_check_act_status(&radeon_connector->mst_port->mst_mgr);
  369. ret = drm_dp_update_payload_part2(&radeon_connector->mst_port->mst_mgr);
  370. break;
  371. case DRM_MODE_DPMS_STANDBY:
  372. case DRM_MODE_DPMS_SUSPEND:
  373. case DRM_MODE_DPMS_OFF:
  374. DRM_ERROR("DPMS OFF %d\n", dig_enc->active_mst_links);
  375. if (!mst_enc->enc_active)
  376. return;
  377. drm_dp_mst_reset_vcpi_slots(&radeon_connector->mst_port->mst_mgr, mst_enc->port);
  378. ret = drm_dp_update_payload_part1(&radeon_connector->mst_port->mst_mgr);
  379. drm_dp_check_act_status(&radeon_connector->mst_port->mst_mgr);
  380. /* and this can also fail */
  381. drm_dp_update_payload_part2(&radeon_connector->mst_port->mst_mgr);
  382. drm_dp_mst_deallocate_vcpi(&radeon_connector->mst_port->mst_mgr, mst_enc->port);
  383. mst_enc->enc_active = false;
  384. radeon_dp_mst_update_stream_attribs(radeon_connector->mst_port, primary);
  385. radeon_dp_mst_set_be_cntl(primary, mst_enc,
  386. radeon_connector->mst_port->hpd.hpd, false);
  387. atombios_dig_encoder_setup2(&primary->base, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0,
  388. mst_enc->fe);
  389. if (!mst_enc->fe_from_be)
  390. radeon_atom_release_dig_encoder(rdev, mst_enc->fe);
  391. mst_enc->fe_from_be = false;
  392. dig_enc->active_mst_links--;
  393. if (dig_enc->active_mst_links == 0) {
  394. /* drop link */
  395. }
  396. break;
  397. }
  398. }
  399. static bool radeon_mst_mode_fixup(struct drm_encoder *encoder,
  400. const struct drm_display_mode *mode,
  401. struct drm_display_mode *adjusted_mode)
  402. {
  403. struct radeon_encoder_mst *mst_enc;
  404. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  405. int bpp = 24;
  406. mst_enc = radeon_encoder->enc_priv;
  407. mst_enc->pbn = drm_dp_calc_pbn_mode(adjusted_mode->clock, bpp);
  408. mst_enc->primary->active_device = mst_enc->primary->devices & mst_enc->connector->devices;
  409. DRM_DEBUG_KMS("setting active device to %08x from %08x %08x for encoder %d\n",
  410. mst_enc->primary->active_device, mst_enc->primary->devices,
  411. mst_enc->connector->devices, mst_enc->primary->base.encoder_type);
  412. drm_mode_set_crtcinfo(adjusted_mode, 0);
  413. {
  414. struct radeon_connector_atom_dig *dig_connector;
  415. dig_connector = mst_enc->connector->con_priv;
  416. dig_connector->dp_lane_count = drm_dp_max_lane_count(dig_connector->dpcd);
  417. dig_connector->dp_clock = drm_dp_max_link_rate(dig_connector->dpcd);
  418. DRM_DEBUG_KMS("dig clock %p %d %d\n", dig_connector,
  419. dig_connector->dp_lane_count, dig_connector->dp_clock);
  420. }
  421. return true;
  422. }
  423. static void radeon_mst_encoder_prepare(struct drm_encoder *encoder)
  424. {
  425. struct radeon_connector *radeon_connector;
  426. struct radeon_encoder *radeon_encoder, *primary;
  427. struct radeon_encoder_mst *mst_enc;
  428. struct radeon_encoder_atom_dig *dig_enc;
  429. radeon_connector = radeon_mst_find_connector(encoder);
  430. if (!radeon_connector) {
  431. DRM_DEBUG_KMS("failed to find connector %p\n", encoder);
  432. return;
  433. }
  434. radeon_encoder = to_radeon_encoder(encoder);
  435. radeon_mst_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
  436. mst_enc = radeon_encoder->enc_priv;
  437. primary = mst_enc->primary;
  438. dig_enc = primary->enc_priv;
  439. mst_enc->port = radeon_connector->port;
  440. if (dig_enc->dig_encoder == -1) {
  441. dig_enc->dig_encoder = radeon_atom_pick_dig_encoder(&primary->base, -1);
  442. primary->offset = radeon_atom_set_enc_offset(dig_enc->dig_encoder);
  443. atombios_set_mst_encoder_crtc_source(encoder, dig_enc->dig_encoder);
  444. }
  445. DRM_DEBUG_KMS("%d %d\n", dig_enc->dig_encoder, primary->offset);
  446. }
  447. static void
  448. radeon_mst_encoder_mode_set(struct drm_encoder *encoder,
  449. struct drm_display_mode *mode,
  450. struct drm_display_mode *adjusted_mode)
  451. {
  452. DRM_DEBUG_KMS("\n");
  453. }
  454. static void radeon_mst_encoder_commit(struct drm_encoder *encoder)
  455. {
  456. radeon_mst_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
  457. DRM_DEBUG_KMS("\n");
  458. }
  459. static const struct drm_encoder_helper_funcs radeon_mst_helper_funcs = {
  460. .dpms = radeon_mst_encoder_dpms,
  461. .mode_fixup = radeon_mst_mode_fixup,
  462. .prepare = radeon_mst_encoder_prepare,
  463. .mode_set = radeon_mst_encoder_mode_set,
  464. .commit = radeon_mst_encoder_commit,
  465. };
  466. void radeon_dp_mst_encoder_destroy(struct drm_encoder *encoder)
  467. {
  468. drm_encoder_cleanup(encoder);
  469. kfree(encoder);
  470. }
  471. static const struct drm_encoder_funcs radeon_dp_mst_enc_funcs = {
  472. .destroy = radeon_dp_mst_encoder_destroy,
  473. };
  474. static struct radeon_encoder *
  475. radeon_dp_create_fake_mst_encoder(struct radeon_connector *connector)
  476. {
  477. struct drm_device *dev = connector->base.dev;
  478. struct radeon_device *rdev = dev->dev_private;
  479. struct radeon_encoder *radeon_encoder;
  480. struct radeon_encoder_mst *mst_enc;
  481. struct drm_encoder *encoder;
  482. const struct drm_connector_helper_funcs *connector_funcs = connector->base.helper_private;
  483. struct drm_encoder *enc_master = connector_funcs->best_encoder(&connector->base);
  484. DRM_DEBUG_KMS("enc master is %p\n", enc_master);
  485. radeon_encoder = kzalloc(sizeof(*radeon_encoder), GFP_KERNEL);
  486. if (!radeon_encoder)
  487. return NULL;
  488. radeon_encoder->enc_priv = kzalloc(sizeof(*mst_enc), GFP_KERNEL);
  489. if (!radeon_encoder->enc_priv) {
  490. kfree(radeon_encoder);
  491. return NULL;
  492. }
  493. encoder = &radeon_encoder->base;
  494. switch (rdev->num_crtc) {
  495. case 1:
  496. encoder->possible_crtcs = 0x1;
  497. break;
  498. case 2:
  499. default:
  500. encoder->possible_crtcs = 0x3;
  501. break;
  502. case 4:
  503. encoder->possible_crtcs = 0xf;
  504. break;
  505. case 6:
  506. encoder->possible_crtcs = 0x3f;
  507. break;
  508. }
  509. drm_encoder_init(dev, &radeon_encoder->base, &radeon_dp_mst_enc_funcs,
  510. DRM_MODE_ENCODER_DPMST);
  511. drm_encoder_helper_add(encoder, &radeon_mst_helper_funcs);
  512. mst_enc = radeon_encoder->enc_priv;
  513. mst_enc->connector = connector;
  514. mst_enc->primary = to_radeon_encoder(enc_master);
  515. radeon_encoder->is_mst_encoder = true;
  516. return radeon_encoder;
  517. }
  518. int
  519. radeon_dp_mst_init(struct radeon_connector *radeon_connector)
  520. {
  521. struct drm_device *dev = radeon_connector->base.dev;
  522. if (!radeon_connector->ddc_bus->has_aux)
  523. return 0;
  524. radeon_connector->mst_mgr.cbs = &mst_cbs;
  525. return drm_dp_mst_topology_mgr_init(&radeon_connector->mst_mgr, dev->dev,
  526. &radeon_connector->ddc_bus->aux, 16, 6,
  527. radeon_connector->base.base.id);
  528. }
  529. int
  530. radeon_dp_mst_probe(struct radeon_connector *radeon_connector)
  531. {
  532. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  533. struct drm_device *dev = radeon_connector->base.dev;
  534. struct radeon_device *rdev = dev->dev_private;
  535. int ret;
  536. u8 msg[1];
  537. if (!radeon_mst)
  538. return 0;
  539. if (!ASIC_IS_DCE5(rdev))
  540. return 0;
  541. if (dig_connector->dpcd[DP_DPCD_REV] < 0x12)
  542. return 0;
  543. ret = drm_dp_dpcd_read(&radeon_connector->ddc_bus->aux, DP_MSTM_CAP, msg,
  544. 1);
  545. if (ret) {
  546. if (msg[0] & DP_MST_CAP) {
  547. DRM_DEBUG_KMS("Sink is MST capable\n");
  548. dig_connector->is_mst = true;
  549. } else {
  550. DRM_DEBUG_KMS("Sink is not MST capable\n");
  551. dig_connector->is_mst = false;
  552. }
  553. }
  554. drm_dp_mst_topology_mgr_set_mst(&radeon_connector->mst_mgr,
  555. dig_connector->is_mst);
  556. return dig_connector->is_mst;
  557. }
  558. int
  559. radeon_dp_mst_check_status(struct radeon_connector *radeon_connector)
  560. {
  561. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  562. int retry;
  563. if (dig_connector->is_mst) {
  564. u8 esi[16] = { 0 };
  565. int dret;
  566. int ret = 0;
  567. bool handled;
  568. dret = drm_dp_dpcd_read(&radeon_connector->ddc_bus->aux,
  569. DP_SINK_COUNT_ESI, esi, 8);
  570. go_again:
  571. if (dret == 8) {
  572. DRM_DEBUG_KMS("got esi %02x %02x %02x\n", esi[0], esi[1], esi[2]);
  573. ret = drm_dp_mst_hpd_irq(&radeon_connector->mst_mgr, esi, &handled);
  574. if (handled) {
  575. for (retry = 0; retry < 3; retry++) {
  576. int wret;
  577. wret = drm_dp_dpcd_write(&radeon_connector->ddc_bus->aux,
  578. DP_SINK_COUNT_ESI + 1, &esi[1], 3);
  579. if (wret == 3)
  580. break;
  581. }
  582. dret = drm_dp_dpcd_read(&radeon_connector->ddc_bus->aux,
  583. DP_SINK_COUNT_ESI, esi, 8);
  584. if (dret == 8) {
  585. DRM_DEBUG_KMS("got esi2 %02x %02x %02x\n", esi[0], esi[1], esi[2]);
  586. goto go_again;
  587. }
  588. } else
  589. ret = 0;
  590. return ret;
  591. } else {
  592. DRM_DEBUG_KMS("failed to get ESI - device may have failed %d\n", ret);
  593. dig_connector->is_mst = false;
  594. drm_dp_mst_topology_mgr_set_mst(&radeon_connector->mst_mgr,
  595. dig_connector->is_mst);
  596. /* send a hotplug event */
  597. }
  598. }
  599. return -EINVAL;
  600. }
  601. #if defined(CONFIG_DEBUG_FS)
  602. static int radeon_debugfs_mst_info(struct seq_file *m, void *data)
  603. {
  604. struct drm_info_node *node = (struct drm_info_node *)m->private;
  605. struct drm_device *dev = node->minor->dev;
  606. struct drm_connector *connector;
  607. struct radeon_connector *radeon_connector;
  608. struct radeon_connector_atom_dig *dig_connector;
  609. int i;
  610. drm_modeset_lock_all(dev);
  611. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  612. if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
  613. continue;
  614. radeon_connector = to_radeon_connector(connector);
  615. dig_connector = radeon_connector->con_priv;
  616. if (radeon_connector->is_mst_connector)
  617. continue;
  618. if (!dig_connector->is_mst)
  619. continue;
  620. drm_dp_mst_dump_topology(m, &radeon_connector->mst_mgr);
  621. for (i = 0; i < radeon_connector->enabled_attribs; i++)
  622. seq_printf(m, "attrib %d: %d %d\n", i,
  623. radeon_connector->cur_stream_attribs[i].fe,
  624. radeon_connector->cur_stream_attribs[i].slots);
  625. }
  626. drm_modeset_unlock_all(dev);
  627. return 0;
  628. }
  629. static struct drm_info_list radeon_debugfs_mst_list[] = {
  630. {"radeon_mst_info", &radeon_debugfs_mst_info, 0, NULL},
  631. };
  632. #endif
  633. int radeon_mst_debugfs_init(struct radeon_device *rdev)
  634. {
  635. #if defined(CONFIG_DEBUG_FS)
  636. return radeon_debugfs_add_files(rdev, radeon_debugfs_mst_list, 1);
  637. #endif
  638. return 0;
  639. }