atombios_dp.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. #define DP_LINK_STATUS_SIZE 6
  33. bool radeon_process_aux_ch(struct radeon_i2c_chan *chan, u8 *req_bytes,
  34. int num_bytes, u8 *read_byte,
  35. u8 read_buf_len, u8 delay)
  36. {
  37. struct drm_device *dev = chan->dev;
  38. struct radeon_device *rdev = dev->dev_private;
  39. PROCESS_AUX_CHANNEL_TRANSACTION_PS_ALLOCATION args;
  40. int index = GetIndexIntoMasterTable(COMMAND, ProcessAuxChannelTransaction);
  41. unsigned char *base;
  42. memset(&args, 0, sizeof(args));
  43. base = (unsigned char *)rdev->mode_info.atom_context->scratch;
  44. memcpy(base, req_bytes, num_bytes);
  45. args.lpAuxRequest = 0;
  46. args.lpDataOut = 16;
  47. args.ucDataOutLen = 0;
  48. args.ucChannelID = chan->rec.i2c_id;
  49. args.ucDelay = delay / 10;
  50. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  51. if (args.ucReplyStatus) {
  52. DRM_ERROR("failed to get auxch %02x%02x %02x %02x 0x%02x %02x\n",
  53. req_bytes[1], req_bytes[0], req_bytes[2], req_bytes[3],
  54. chan->rec.i2c_id, args.ucReplyStatus);
  55. return false;
  56. }
  57. if (args.ucDataOutLen && read_byte && read_buf_len) {
  58. if (read_buf_len < args.ucDataOutLen) {
  59. DRM_ERROR("Buffer to small for return answer %d %d\n",
  60. read_buf_len, args.ucDataOutLen);
  61. return false;
  62. }
  63. {
  64. int len = min(read_buf_len, args.ucDataOutLen);
  65. memcpy(read_byte, base + 16, len);
  66. }
  67. }
  68. return true;
  69. }
  70. int radeon_dp_encoder_service(struct radeon_device *rdev, int action, int dp_clock,
  71. uint8_t ucconfig, uint8_t lane_num)
  72. {
  73. DP_ENCODER_SERVICE_PARAMETERS args;
  74. int index = GetIndexIntoMasterTable(COMMAND, DPEncoderService);
  75. memset(&args, 0, sizeof(args));
  76. args.ucLinkClock = dp_clock / 10;
  77. args.ucConfig = ucconfig;
  78. args.ucAction = action;
  79. args.ucLaneNum = lane_num;
  80. args.ucStatus = 0;
  81. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  82. return args.ucStatus;
  83. }
  84. int radeon_dp_getsinktype(struct radeon_connector *radeon_connector)
  85. {
  86. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  87. struct drm_device *dev = radeon_connector->base.dev;
  88. struct radeon_device *rdev = dev->dev_private;
  89. return radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_GET_SINK_TYPE, 0,
  90. radeon_dig_connector->dp_i2c_bus->rec.i2c_id, 0);
  91. }
  92. union dig_transmitter_control {
  93. DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1;
  94. DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2;
  95. };
  96. bool radeon_dp_aux_native_write(struct radeon_connector *radeon_connector, uint16_t address,
  97. uint8_t send_bytes, uint8_t *send)
  98. {
  99. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  100. struct drm_device *dev = radeon_connector->base.dev;
  101. struct radeon_device *rdev = dev->dev_private;
  102. u8 msg[20];
  103. u8 msg_len, dp_msg_len;
  104. bool ret;
  105. dp_msg_len = 4;
  106. msg[0] = address;
  107. msg[1] = address >> 8;
  108. msg[2] = AUX_NATIVE_WRITE << 4;
  109. dp_msg_len += send_bytes;
  110. msg[3] = (dp_msg_len << 4) | (send_bytes - 1);
  111. if (send_bytes > 16)
  112. return false;
  113. memcpy(&msg[4], send, send_bytes);
  114. msg_len = 4 + send_bytes;
  115. ret = radeon_process_aux_ch(radeon_dig_connector->dp_i2c_bus, msg, msg_len, NULL, 0, 0);
  116. return ret;
  117. }
  118. bool radeon_dp_aux_native_read(struct radeon_connector *radeon_connector, uint16_t address,
  119. uint8_t delay, uint8_t expected_bytes,
  120. uint8_t *read_p)
  121. {
  122. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  123. struct drm_device *dev = radeon_connector->base.dev;
  124. struct radeon_device *rdev = dev->dev_private;
  125. u8 msg[20];
  126. u8 msg_len, dp_msg_len;
  127. bool ret = false;
  128. msg_len = 4;
  129. dp_msg_len = 4;
  130. msg[0] = address;
  131. msg[1] = address >> 8;
  132. msg[2] = AUX_NATIVE_READ << 4;
  133. msg[3] = (dp_msg_len) << 4;
  134. msg[3] |= expected_bytes - 1;
  135. ret = radeon_process_aux_ch(radeon_dig_connector->dp_i2c_bus, msg, msg_len, read_p, expected_bytes, delay);
  136. return ret;
  137. }
  138. void radeon_dp_getdpcd(struct radeon_connector *radeon_connector)
  139. {
  140. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  141. u8 msg[25];
  142. int ret;
  143. ret = radeon_dp_aux_native_read(radeon_connector, DP_DPCD_REV, 0, 8, msg);
  144. if (ret) {
  145. memcpy(radeon_dig_connector->dpcd, msg, 8);
  146. {
  147. int i;
  148. printk("DPCD: ");
  149. for (i = 0; i < 8; i++)
  150. printk("%02x ", msg[i]);
  151. printk("\n");
  152. }
  153. }
  154. radeon_dig_connector->dpcd[0] = 0;
  155. return;
  156. }
  157. static bool atom_dp_get_link_status(struct radeon_connector *radeon_connector,
  158. u8 link_status[DP_LINK_STATUS_SIZE])
  159. {
  160. int ret;
  161. ret = radeon_dp_aux_native_read(radeon_connector, DP_LANE0_1_STATUS, 100,
  162. DP_LINK_STATUS_SIZE, link_status);
  163. if (!ret) {
  164. DRM_ERROR("displayport link status failed\n");
  165. return false;
  166. }
  167. DRM_INFO("link status %02x %02x %02x %02x %02x %02x\n",
  168. link_status[0], link_status[1], link_status[2],
  169. link_status[3], link_status[4], link_status[5]);
  170. return true;
  171. }
  172. static void dp_set_power(struct radeon_connector *radeon_connector, u8 power_state)
  173. {
  174. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  175. if (radeon_dig_connector->dpcd[0] >= 0x11) {
  176. radeon_dp_aux_native_write(radeon_connector, DP_SET_POWER, 1,
  177. &power_state);
  178. }
  179. }
  180. static void dp_update_dpvs_emph(struct radeon_connector *radeon_connector,
  181. u8 train_set[4])
  182. {
  183. struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  184. // radeon_dp_digtransmitter_setup_vsemph();
  185. radeon_dp_aux_native_write(radeon_connector, DP_TRAINING_LANE0_SET,
  186. 0/* lc */, train_set);
  187. }
  188. static void dp_set_training(struct radeon_connector *radeon_connector,
  189. u8 training)
  190. {
  191. radeon_dp_aux_native_write(radeon_connector, DP_TRAINING_PATTERN_SET,
  192. 1, &training);
  193. }
  194. int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
  195. uint8_t write_byte, uint8_t *read_byte)
  196. {
  197. struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
  198. struct radeon_i2c_chan *auxch = (struct radeon_i2c_chan *)adapter;
  199. int ret = 0;
  200. uint16_t address = algo_data->address;
  201. uint8_t msg[5];
  202. uint8_t reply[2];
  203. int msg_len, dp_msg_len;
  204. int reply_bytes;
  205. /* Set up the command byte */
  206. if (mode & MODE_I2C_READ)
  207. msg[2] = AUX_I2C_READ << 4;
  208. else
  209. msg[2] = AUX_I2C_WRITE << 4;
  210. if (!(mode & MODE_I2C_STOP))
  211. msg[2] |= AUX_I2C_MOT << 4;
  212. msg[0] = address;
  213. msg[1] = address >> 8;
  214. reply_bytes = 1;
  215. msg_len = 4;
  216. dp_msg_len = 3;
  217. switch (mode) {
  218. case MODE_I2C_WRITE:
  219. msg[4] = write_byte;
  220. msg_len++;
  221. dp_msg_len += 2;
  222. break;
  223. case MODE_I2C_READ:
  224. dp_msg_len += 1;
  225. break;
  226. default:
  227. break;
  228. }
  229. msg[3] = (dp_msg_len) << 4;
  230. ret = radeon_process_aux_ch(auxch, msg, msg_len, reply, reply_bytes, 0);
  231. if (ret) {
  232. if (read_byte)
  233. *read_byte = reply[0];
  234. return reply_bytes;
  235. }
  236. return -EREMOTEIO;
  237. }