atombios_dp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include "atom-bits.h"
  31. #include "drm_dp_helper.h"
  32. /* move these to drm_dp_helper.c/h */
  33. #define DP_LINK_CONFIGURATION_SIZE 9
  34. #define DP_LINK_STATUS_SIZE 6
  35. #define DP_DPCD_SIZE 8
  36. static char *voltage_names[] = {
  37. "0.4V", "0.6V", "0.8V", "1.2V"
  38. };
  39. static char *pre_emph_names[] = {
  40. "0dB", "3.5dB", "6dB", "9.5dB"
  41. };
  42. static char *link_train_names[] = {
  43. "pattern 1", "pattern 2", "idle", "off"
  44. };
  45. static const int dp_clocks[] = {
  46. 54000, // 1 lane, 1.62 Ghz
  47. 90000, // 1 lane, 2.70 Ghz
  48. 108000, // 2 lane, 1.62 Ghz
  49. 180000, // 2 lane, 2.70 Ghz
  50. 216000, // 4 lane, 1.62 Ghz
  51. 360000, // 4 lane, 2.70 Ghz
  52. };
  53. static const int num_dp_clocks = sizeof(dp_clocks) / sizeof(int);
  54. /* common helper functions */
  55. static int dp_lanes_for_mode_clock(u8 dpcd[DP_DPCD_SIZE], int mode_clock)
  56. {
  57. int i;
  58. u8 max_link_bw;
  59. u8 max_lane_count;
  60. if (!dpcd)
  61. return 0;
  62. max_link_bw = dpcd[DP_MAX_LINK_RATE];
  63. max_lane_count = dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
  64. switch (max_link_bw) {
  65. case DP_LINK_BW_1_62:
  66. default:
  67. for (i = 0; i < num_dp_clocks; i++) {
  68. if (i % 2)
  69. continue;
  70. switch (max_lane_count) {
  71. case 1:
  72. if (i > 1)
  73. return 0;
  74. break;
  75. case 2:
  76. if (i > 3)
  77. return 0;
  78. break;
  79. case 4:
  80. default:
  81. break;
  82. }
  83. if (dp_clocks[i] > mode_clock) {
  84. if (i < 2)
  85. return 1;
  86. else if (i < 4)
  87. return 2;
  88. else
  89. return 4;
  90. }
  91. }
  92. break;
  93. case DP_LINK_BW_2_7:
  94. for (i = 0; i < num_dp_clocks; i++) {
  95. switch (max_lane_count) {
  96. case 1:
  97. if (i > 1)
  98. return 0;
  99. break;
  100. case 2:
  101. if (i > 3)
  102. return 0;
  103. break;
  104. case 4:
  105. default:
  106. break;
  107. }
  108. if (dp_clocks[i] > mode_clock) {
  109. if (i < 2)
  110. return 1;
  111. else if (i < 4)
  112. return 2;
  113. else
  114. return 4;
  115. }
  116. }
  117. break;
  118. }
  119. return 0;
  120. }
  121. static int dp_link_clock_for_mode_clock(u8 dpcd[DP_DPCD_SIZE], int mode_clock)
  122. {
  123. int i;
  124. u8 max_link_bw;
  125. u8 max_lane_count;
  126. if (!dpcd)
  127. return 0;
  128. max_link_bw = dpcd[DP_MAX_LINK_RATE];
  129. max_lane_count = dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
  130. switch (max_link_bw) {
  131. case DP_LINK_BW_1_62:
  132. default:
  133. for (i = 0; i < num_dp_clocks; i++) {
  134. if (i % 2)
  135. continue;
  136. switch (max_lane_count) {
  137. case 1:
  138. if (i > 1)
  139. return 0;
  140. break;
  141. case 2:
  142. if (i > 3)
  143. return 0;
  144. break;
  145. case 4:
  146. default:
  147. break;
  148. }
  149. if (dp_clocks[i] > mode_clock)
  150. return 162000;
  151. }
  152. break;
  153. case DP_LINK_BW_2_7:
  154. for (i = 0; i < num_dp_clocks; i++) {
  155. switch (max_lane_count) {
  156. case 1:
  157. if (i > 1)
  158. return 0;
  159. break;
  160. case 2:
  161. if (i > 3)
  162. return 0;
  163. break;
  164. case 4:
  165. default:
  166. break;
  167. }
  168. if (dp_clocks[i] > mode_clock)
  169. return (i % 2) ? 270000 : 162000;
  170. }
  171. }
  172. return 0;
  173. }
  174. int dp_mode_valid(u8 dpcd[DP_DPCD_SIZE], int mode_clock)
  175. {
  176. int lanes = dp_lanes_for_mode_clock(dpcd, mode_clock);
  177. int bw = dp_lanes_for_mode_clock(dpcd, mode_clock);
  178. if ((lanes == 0) || (bw == 0))
  179. return MODE_CLOCK_HIGH;
  180. return MODE_OK;
  181. }
  182. static u8 dp_link_status(u8 link_status[DP_LINK_STATUS_SIZE], int r)
  183. {
  184. return link_status[r - DP_LANE0_1_STATUS];
  185. }
  186. static u8 dp_get_lane_status(u8 link_status[DP_LINK_STATUS_SIZE],
  187. int lane)
  188. {
  189. int i = DP_LANE0_1_STATUS + (lane >> 1);
  190. int s = (lane & 1) * 4;
  191. u8 l = dp_link_status(link_status, i);
  192. return (l >> s) & 0xf;
  193. }
  194. static bool dp_clock_recovery_ok(u8 link_status[DP_LINK_STATUS_SIZE],
  195. int lane_count)
  196. {
  197. int lane;
  198. u8 lane_status;
  199. for (lane = 0; lane < lane_count; lane++) {
  200. lane_status = dp_get_lane_status(link_status, lane);
  201. if ((lane_status & DP_LANE_CR_DONE) == 0)
  202. return false;
  203. }
  204. return true;
  205. }
  206. static bool dp_channel_eq_ok(u8 link_status[DP_LINK_STATUS_SIZE],
  207. int lane_count)
  208. {
  209. u8 lane_align;
  210. u8 lane_status;
  211. int lane;
  212. lane_align = dp_link_status(link_status,
  213. DP_LANE_ALIGN_STATUS_UPDATED);
  214. if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
  215. return false;
  216. for (lane = 0; lane < lane_count; lane++) {
  217. lane_status = dp_get_lane_status(link_status, lane);
  218. if ((lane_status & DP_CHANNEL_EQ_BITS) != DP_CHANNEL_EQ_BITS)
  219. return false;
  220. }
  221. return true;
  222. }
  223. static u8 dp_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
  224. int lane)
  225. {
  226. int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
  227. int s = ((lane & 1) ?
  228. DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
  229. DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
  230. u8 l = dp_link_status(link_status, i);
  231. return ((l >> s) & 0x3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
  232. }
  233. static u8 dp_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
  234. int lane)
  235. {
  236. int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
  237. int s = ((lane & 1) ?
  238. DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
  239. DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
  240. u8 l = dp_link_status(link_status, i);
  241. return ((l >> s) & 0x3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
  242. }
  243. /* XXX fix me -- chip specific */
  244. #define DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_1200
  245. static u8 dp_pre_emphasis_max(u8 voltage_swing)
  246. {
  247. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  248. case DP_TRAIN_VOLTAGE_SWING_400:
  249. return DP_TRAIN_PRE_EMPHASIS_6;
  250. case DP_TRAIN_VOLTAGE_SWING_600:
  251. return DP_TRAIN_PRE_EMPHASIS_6;
  252. case DP_TRAIN_VOLTAGE_SWING_800:
  253. return DP_TRAIN_PRE_EMPHASIS_3_5;
  254. case DP_TRAIN_VOLTAGE_SWING_1200:
  255. default:
  256. return DP_TRAIN_PRE_EMPHASIS_0;
  257. }
  258. }
  259. static void dp_get_adjust_train(u8 link_status[DP_LINK_STATUS_SIZE],
  260. int lane_count,
  261. u8 train_set[4])
  262. {
  263. u8 v = 0;
  264. u8 p = 0;
  265. int lane;
  266. for (lane = 0; lane < lane_count; lane++) {
  267. u8 this_v = dp_get_adjust_request_voltage(link_status, lane);
  268. u8 this_p = dp_get_adjust_request_pre_emphasis(link_status, lane);
  269. DRM_INFO("requested signal parameters: lane %d voltage %s pre_emph %s\n",
  270. lane,
  271. voltage_names[this_v >> DP_TRAIN_VOLTAGE_SWING_SHIFT],
  272. pre_emph_names[this_p >> DP_TRAIN_PRE_EMPHASIS_SHIFT]);
  273. if (this_v > v)
  274. v = this_v;
  275. if (this_p > p)
  276. p = this_p;
  277. }
  278. if (v >= DP_VOLTAGE_MAX)
  279. v = DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
  280. if (p >= dp_pre_emphasis_max(v))
  281. p = dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
  282. DRM_INFO("using signal parameters: voltage %s pre_emph %s\n",
  283. voltage_names[(v & DP_TRAIN_VOLTAGE_SWING_MASK) >> DP_TRAIN_VOLTAGE_SWING_SHIFT],
  284. pre_emph_names[(p & DP_TRAIN_PRE_EMPHASIS_MASK) >> DP_TRAIN_PRE_EMPHASIS_SHIFT]);
  285. for (lane = 0; lane < 4; lane++)
  286. train_set[lane] = v | p;
  287. }
  288. /* radeon aux chan functions */
  289. bool radeon_process_aux_ch(struct radeon_i2c_chan *chan, u8 *req_bytes,
  290. int num_bytes, u8 *read_byte,
  291. u8 read_buf_len, u8 delay)
  292. {
  293. struct drm_device *dev = chan->dev;
  294. struct radeon_device *rdev = dev->dev_private;
  295. PROCESS_AUX_CHANNEL_TRANSACTION_PS_ALLOCATION args;
  296. int index = GetIndexIntoMasterTable(COMMAND, ProcessAuxChannelTransaction);
  297. unsigned char *base;
  298. memset(&args, 0, sizeof(args));
  299. base = (unsigned char *)rdev->mode_info.atom_context->scratch;
  300. memcpy(base, req_bytes, num_bytes);
  301. args.lpAuxRequest = 0;
  302. args.lpDataOut = 16;
  303. args.ucDataOutLen = 0;
  304. args.ucChannelID = chan->rec.i2c_id;
  305. args.ucDelay = delay / 10;
  306. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  307. if (args.ucReplyStatus) {
  308. DRM_ERROR("failed to get auxch %02x%02x %02x %02x 0x%02x %02x\n",
  309. req_bytes[1], req_bytes[0], req_bytes[2], req_bytes[3],
  310. chan->rec.i2c_id, args.ucReplyStatus);
  311. return false;
  312. }
  313. if (args.ucDataOutLen && read_byte && read_buf_len) {
  314. if (read_buf_len < args.ucDataOutLen) {
  315. DRM_ERROR("Buffer to small for return answer %d %d\n",
  316. read_buf_len, args.ucDataOutLen);
  317. return false;
  318. }
  319. {
  320. int len = min(read_buf_len, args.ucDataOutLen);
  321. memcpy(read_byte, base + 16, len);
  322. }
  323. }
  324. return true;
  325. }
  326. bool radeon_dp_aux_native_write(struct radeon_connector *radeon_connector, uint16_t address,
  327. uint8_t send_bytes, uint8_t *send)
  328. {
  329. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  330. u8 msg[20];
  331. u8 msg_len, dp_msg_len;
  332. bool ret;
  333. dp_msg_len = 4;
  334. msg[0] = address;
  335. msg[1] = address >> 8;
  336. msg[2] = AUX_NATIVE_WRITE << 4;
  337. dp_msg_len += send_bytes;
  338. msg[3] = (dp_msg_len << 4) | (send_bytes - 1);
  339. if (send_bytes > 16)
  340. return false;
  341. memcpy(&msg[4], send, send_bytes);
  342. msg_len = 4 + send_bytes;
  343. ret = radeon_process_aux_ch(dig_connector->dp_i2c_bus, msg, msg_len, NULL, 0, 0);
  344. return ret;
  345. }
  346. bool radeon_dp_aux_native_read(struct radeon_connector *radeon_connector, uint16_t address,
  347. uint8_t delay, uint8_t expected_bytes,
  348. uint8_t *read_p)
  349. {
  350. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  351. u8 msg[20];
  352. u8 msg_len, dp_msg_len;
  353. bool ret = false;
  354. msg_len = 4;
  355. dp_msg_len = 4;
  356. msg[0] = address;
  357. msg[1] = address >> 8;
  358. msg[2] = AUX_NATIVE_READ << 4;
  359. msg[3] = (dp_msg_len) << 4;
  360. msg[3] |= expected_bytes - 1;
  361. ret = radeon_process_aux_ch(dig_connector->dp_i2c_bus, msg, msg_len, read_p, expected_bytes, delay);
  362. return ret;
  363. }
  364. /* radeon dp functions */
  365. static u8 radeon_dp_encoder_service(struct radeon_device *rdev, int action, int dp_clock,
  366. uint8_t ucconfig, uint8_t lane_num)
  367. {
  368. DP_ENCODER_SERVICE_PARAMETERS args;
  369. int index = GetIndexIntoMasterTable(COMMAND, DPEncoderService);
  370. memset(&args, 0, sizeof(args));
  371. args.ucLinkClock = dp_clock / 10;
  372. args.ucConfig = ucconfig;
  373. args.ucAction = action;
  374. args.ucLaneNum = lane_num;
  375. args.ucStatus = 0;
  376. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  377. return args.ucStatus;
  378. }
  379. u8 radeon_dp_getsinktype(struct radeon_connector *radeon_connector)
  380. {
  381. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  382. struct drm_device *dev = radeon_connector->base.dev;
  383. struct radeon_device *rdev = dev->dev_private;
  384. return radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_GET_SINK_TYPE, 0,
  385. dig_connector->dp_i2c_bus->rec.i2c_id, 0);
  386. }
  387. void radeon_dp_getdpcd(struct radeon_connector *radeon_connector)
  388. {
  389. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  390. u8 msg[25];
  391. int ret;
  392. ret = radeon_dp_aux_native_read(radeon_connector, DP_DPCD_REV, 0, 8, msg);
  393. if (ret) {
  394. memcpy(dig_connector->dpcd, msg, 8);
  395. {
  396. int i;
  397. printk("DPCD: ");
  398. for (i = 0; i < 8; i++)
  399. printk("%02x ", msg[i]);
  400. printk("\n");
  401. }
  402. return;
  403. }
  404. dig_connector->dpcd[0] = 0;
  405. return;
  406. }
  407. void radeon_dp_set_link_config(struct drm_connector *connector,
  408. struct drm_display_mode *mode)
  409. {
  410. struct radeon_connector *radeon_connector;
  411. struct radeon_connector_atom_dig *dig_connector;
  412. if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
  413. return;
  414. radeon_connector = to_radeon_connector(connector);
  415. if (!radeon_connector->con_priv)
  416. return;
  417. dig_connector = radeon_connector->con_priv;
  418. dig_connector->dp_clock =
  419. dp_link_clock_for_mode_clock(dig_connector->dpcd, mode->clock);
  420. dig_connector->dp_lane_count =
  421. dp_lanes_for_mode_clock(dig_connector->dpcd, mode->clock);
  422. }
  423. int radeon_dp_mode_valid_helper(struct radeon_connector *radeon_connector,
  424. struct drm_display_mode *mode)
  425. {
  426. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  427. return dp_mode_valid(dig_connector->dpcd, mode->clock);
  428. }
  429. static bool atom_dp_get_link_status(struct radeon_connector *radeon_connector,
  430. u8 link_status[DP_LINK_STATUS_SIZE])
  431. {
  432. int ret;
  433. ret = radeon_dp_aux_native_read(radeon_connector, DP_LANE0_1_STATUS, 100,
  434. DP_LINK_STATUS_SIZE, link_status);
  435. if (!ret) {
  436. DRM_ERROR("displayport link status failed\n");
  437. return false;
  438. }
  439. DRM_INFO("link status %02x %02x %02x %02x %02x %02x\n",
  440. link_status[0], link_status[1], link_status[2],
  441. link_status[3], link_status[4], link_status[5]);
  442. return true;
  443. }
  444. static void dp_set_power(struct radeon_connector *radeon_connector, u8 power_state)
  445. {
  446. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  447. if (dig_connector->dpcd[0] >= 0x11) {
  448. radeon_dp_aux_native_write(radeon_connector, DP_SET_POWER, 1,
  449. &power_state);
  450. }
  451. }
  452. static void dp_set_downspread(struct radeon_connector *radeon_connector, u8 downspread)
  453. {
  454. radeon_dp_aux_native_write(radeon_connector, DP_DOWNSPREAD_CTRL, 1,
  455. &downspread);
  456. }
  457. static void dp_set_link_bw_lanes(struct radeon_connector *radeon_connector,
  458. u8 link_configuration[DP_LINK_CONFIGURATION_SIZE])
  459. {
  460. radeon_dp_aux_native_write(radeon_connector, DP_LINK_BW_SET, 2,
  461. link_configuration);
  462. }
  463. static void dp_update_dpvs_emph(struct radeon_connector *radeon_connector,
  464. struct drm_encoder *encoder,
  465. u8 train_set[4])
  466. {
  467. struct radeon_connector_atom_dig *dig_connector = radeon_connector->con_priv;
  468. int i;
  469. for (i = 0; i < dig_connector->dp_lane_count; i++)
  470. atombios_dig_transmitter_setup(encoder,
  471. ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH,
  472. i, train_set[i]);
  473. radeon_dp_aux_native_write(radeon_connector, DP_TRAINING_LANE0_SET,
  474. dig_connector->dp_lane_count, train_set);
  475. }
  476. static void dp_set_training(struct radeon_connector *radeon_connector,
  477. u8 training)
  478. {
  479. radeon_dp_aux_native_write(radeon_connector, DP_TRAINING_PATTERN_SET,
  480. 1, &training);
  481. }
  482. void dp_link_train(struct drm_encoder *encoder,
  483. struct drm_connector *connector)
  484. {
  485. struct drm_device *dev = encoder->dev;
  486. struct radeon_device *rdev = dev->dev_private;
  487. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  488. struct radeon_encoder_atom_dig *dig;
  489. struct radeon_connector *radeon_connector;
  490. struct radeon_connector_atom_dig *dig_connector;
  491. int enc_id = 0;
  492. bool clock_recovery, channel_eq;
  493. u8 link_status[DP_LINK_STATUS_SIZE];
  494. u8 link_configuration[DP_LINK_CONFIGURATION_SIZE];
  495. u8 tries, voltage;
  496. u8 train_set[4];
  497. int i;
  498. if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
  499. return;
  500. if (!radeon_encoder->enc_priv)
  501. return;
  502. dig = radeon_encoder->enc_priv;
  503. radeon_connector = to_radeon_connector(connector);
  504. if (!radeon_connector->con_priv)
  505. return;
  506. dig_connector = radeon_connector->con_priv;
  507. if (ASIC_IS_DCE32(rdev)) {
  508. if (dig->dig_block)
  509. enc_id |= ATOM_DP_CONFIG_DIG2_ENCODER;
  510. else
  511. enc_id |= ATOM_DP_CONFIG_DIG1_ENCODER;
  512. if (dig_connector->linkb)
  513. enc_id |= ATOM_DP_CONFIG_LINK_B;
  514. else
  515. enc_id |= ATOM_DP_CONFIG_LINK_A;
  516. } else {
  517. if (dig_connector->linkb)
  518. enc_id |= ATOM_DP_CONFIG_DIG2_ENCODER | ATOM_DP_CONFIG_LINK_B;
  519. else
  520. enc_id |= ATOM_DP_CONFIG_DIG1_ENCODER | ATOM_DP_CONFIG_LINK_A;
  521. }
  522. memset(link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
  523. if (dig_connector->dp_clock == 270000)
  524. link_configuration[0] = DP_LINK_BW_2_7;
  525. else
  526. link_configuration[0] = DP_LINK_BW_1_62;
  527. link_configuration[1] = dig_connector->dp_lane_count;
  528. if (dig_connector->dpcd[0] >= 0x11)
  529. link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
  530. /* power up the sink */
  531. dp_set_power(radeon_connector, DP_SET_POWER_D0);
  532. /* disable the training pattern on the sink */
  533. dp_set_training(radeon_connector, DP_TRAINING_PATTERN_DISABLE);
  534. /* set link bw and lanes on the sink */
  535. dp_set_link_bw_lanes(radeon_connector, link_configuration);
  536. /* disable downspread on the sink */
  537. dp_set_downspread(radeon_connector, 0);
  538. /* start training on the source */
  539. radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_START,
  540. dig_connector->dp_clock, enc_id, 0);
  541. /* set training pattern 1 on the source */
  542. radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_PATTERN_SEL,
  543. dig_connector->dp_clock, enc_id, 0);
  544. /* set initial vs/emph */
  545. memset(train_set, 0, 4);
  546. dp_update_dpvs_emph(radeon_connector, encoder, train_set);
  547. udelay(400);
  548. /* set training pattern 1 on the sink */
  549. dp_set_training(radeon_connector, DP_TRAINING_PATTERN_1);
  550. /* clock recovery loop */
  551. clock_recovery = false;
  552. tries = 0;
  553. voltage = 0xff;
  554. for (;;) {
  555. udelay(100);
  556. if (!atom_dp_get_link_status(radeon_connector, link_status))
  557. break;
  558. if (dp_clock_recovery_ok(link_status, dig_connector->dp_lane_count)) {
  559. clock_recovery = true;
  560. break;
  561. }
  562. for (i = 0; i < dig_connector->dp_lane_count; i++) {
  563. if ((train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
  564. break;
  565. }
  566. if (i == dig_connector->dp_lane_count) {
  567. DRM_ERROR("clock recovery reached max voltage\n");
  568. break;
  569. }
  570. if ((train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
  571. ++tries;
  572. if (tries == 5) {
  573. DRM_ERROR("clock recovery tried 5 times\n");
  574. break;
  575. }
  576. } else
  577. tries = 0;
  578. voltage = train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
  579. /* Compute new train_set as requested by sink */
  580. dp_get_adjust_train(link_status, dig_connector->dp_lane_count, train_set);
  581. dp_update_dpvs_emph(radeon_connector, encoder, train_set);
  582. }
  583. if (!clock_recovery)
  584. DRM_ERROR("clock recovery failed\n");
  585. else
  586. DRM_INFO("clock recovery at voltage %d pre-emphasis %d\n",
  587. train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK,
  588. (train_set[0] & DP_TRAIN_PRE_EMPHASIS_MASK) >>
  589. DP_TRAIN_PRE_EMPHASIS_SHIFT);
  590. /* set training pattern 2 on the sink */
  591. dp_set_training(radeon_connector, DP_TRAINING_PATTERN_2);
  592. /* set training pattern 2 on the source */
  593. radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_PATTERN_SEL,
  594. dig_connector->dp_clock, enc_id, 1);
  595. /* channel equalization loop */
  596. tries = 0;
  597. channel_eq = false;
  598. for (;;) {
  599. udelay(400);
  600. if (!atom_dp_get_link_status(radeon_connector, link_status))
  601. break;
  602. if (dp_channel_eq_ok(link_status, dig_connector->dp_lane_count)) {
  603. channel_eq = true;
  604. break;
  605. }
  606. /* Try 5 times */
  607. if (tries > 5) {
  608. DRM_ERROR("channel eq failed: 5 tries\n");
  609. break;
  610. }
  611. /* Compute new train_set as requested by sink */
  612. dp_get_adjust_train(link_status, dig_connector->dp_lane_count, train_set);
  613. dp_update_dpvs_emph(radeon_connector, encoder, train_set);
  614. tries++;
  615. }
  616. if (!channel_eq)
  617. DRM_ERROR("channel eq failed\n");
  618. else
  619. DRM_INFO("channel eq at voltage %d pre-emphasis %d\n",
  620. train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK,
  621. (train_set[0] & DP_TRAIN_PRE_EMPHASIS_MASK)
  622. >> DP_TRAIN_PRE_EMPHASIS_SHIFT);
  623. /* disable the training pattern on the sink */
  624. dp_set_training(radeon_connector, DP_TRAINING_PATTERN_DISABLE);
  625. radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_COMPLETE,
  626. dig_connector->dp_clock, enc_id, 0);
  627. }
  628. int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
  629. uint8_t write_byte, uint8_t *read_byte)
  630. {
  631. struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
  632. struct radeon_i2c_chan *auxch = (struct radeon_i2c_chan *)adapter;
  633. int ret = 0;
  634. uint16_t address = algo_data->address;
  635. uint8_t msg[5];
  636. uint8_t reply[2];
  637. int msg_len, dp_msg_len;
  638. int reply_bytes;
  639. /* Set up the command byte */
  640. if (mode & MODE_I2C_READ)
  641. msg[2] = AUX_I2C_READ << 4;
  642. else
  643. msg[2] = AUX_I2C_WRITE << 4;
  644. if (!(mode & MODE_I2C_STOP))
  645. msg[2] |= AUX_I2C_MOT << 4;
  646. msg[0] = address;
  647. msg[1] = address >> 8;
  648. reply_bytes = 1;
  649. msg_len = 4;
  650. dp_msg_len = 3;
  651. switch (mode) {
  652. case MODE_I2C_WRITE:
  653. msg[4] = write_byte;
  654. msg_len++;
  655. dp_msg_len += 2;
  656. break;
  657. case MODE_I2C_READ:
  658. dp_msg_len += 1;
  659. break;
  660. default:
  661. break;
  662. }
  663. msg[3] = (dp_msg_len) << 4;
  664. ret = radeon_process_aux_ch(auxch, msg, msg_len, reply, reply_bytes, 0);
  665. if (ret) {
  666. if (read_byte)
  667. *read_byte = reply[0];
  668. return reply_bytes;
  669. }
  670. return -EREMOTEIO;
  671. }