dp_link.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  4. *
  5. * Copyright (c) 2009 Keith Packard
  6. *
  7. * Permission to use, copy, modify, distribute, and sell this software and its
  8. * documentation for any purpose is hereby granted without fee, provided that
  9. * the above copyright notice appear in all copies and that both that copyright
  10. * notice and this permission notice appear in supporting documentation, and
  11. * that the name of the copyright holders not be used in advertising or
  12. * publicity pertaining to distribution of the software without specific,
  13. * written prior permission. The copyright holders make no representations
  14. * about the suitability of this software for any purpose. It is provided "as
  15. * is" without express or implied warranty.
  16. *
  17. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  18. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  19. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  21. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  22. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23. * OF THIS SOFTWARE.
  24. */
  25. #include "dp_link.h"
  26. #include "dp_panel.h"
  27. #include "dp_debug.h"
  28. #if defined(CONFIG_SECDP)
  29. #include "secdp.h"
  30. #if defined(CONFIG_SECDP_BIGDATA)
  31. #include <linux/secdp_bigdata.h>
  32. #endif
  33. #endif
  34. enum dynamic_range {
  35. DP_DYNAMIC_RANGE_RGB_VESA = 0x00,
  36. DP_DYNAMIC_RANGE_RGB_CEA = 0x01,
  37. DP_DYNAMIC_RANGE_UNKNOWN = 0xFFFFFFFF,
  38. };
  39. enum audio_sample_rate {
  40. AUDIO_SAMPLE_RATE_32_KHZ = 0x00,
  41. AUDIO_SAMPLE_RATE_44_1_KHZ = 0x01,
  42. AUDIO_SAMPLE_RATE_48_KHZ = 0x02,
  43. AUDIO_SAMPLE_RATE_88_2_KHZ = 0x03,
  44. AUDIO_SAMPLE_RATE_96_KHZ = 0x04,
  45. AUDIO_SAMPLE_RATE_176_4_KHZ = 0x05,
  46. AUDIO_SAMPLE_RATE_192_KHZ = 0x06,
  47. };
  48. enum audio_pattern_type {
  49. AUDIO_TEST_PATTERN_OPERATOR_DEFINED = 0x00,
  50. AUDIO_TEST_PATTERN_SAWTOOTH = 0x01,
  51. };
  52. struct dp_link_request {
  53. u32 test_requested;
  54. u32 test_link_rate;
  55. u32 test_lane_count;
  56. };
  57. struct dp_link_private {
  58. u32 prev_sink_count;
  59. struct device *dev;
  60. struct dp_aux *aux;
  61. struct dp_link dp_link;
  62. struct dp_link_request request;
  63. u8 link_status[DP_LINK_STATUS_SIZE];
  64. };
  65. static char *dp_link_get_audio_test_pattern(u32 pattern)
  66. {
  67. switch (pattern) {
  68. case AUDIO_TEST_PATTERN_OPERATOR_DEFINED:
  69. return DP_LINK_ENUM_STR(AUDIO_TEST_PATTERN_OPERATOR_DEFINED);
  70. case AUDIO_TEST_PATTERN_SAWTOOTH:
  71. return DP_LINK_ENUM_STR(AUDIO_TEST_PATTERN_SAWTOOTH);
  72. default:
  73. return "unknown";
  74. }
  75. }
  76. static char *dp_link_get_audio_sample_rate(u32 rate)
  77. {
  78. switch (rate) {
  79. case AUDIO_SAMPLE_RATE_32_KHZ:
  80. return DP_LINK_ENUM_STR(AUDIO_SAMPLE_RATE_32_KHZ);
  81. case AUDIO_SAMPLE_RATE_44_1_KHZ:
  82. return DP_LINK_ENUM_STR(AUDIO_SAMPLE_RATE_44_1_KHZ);
  83. case AUDIO_SAMPLE_RATE_48_KHZ:
  84. return DP_LINK_ENUM_STR(AUDIO_SAMPLE_RATE_48_KHZ);
  85. case AUDIO_SAMPLE_RATE_88_2_KHZ:
  86. return DP_LINK_ENUM_STR(AUDIO_SAMPLE_RATE_88_2_KHZ);
  87. case AUDIO_SAMPLE_RATE_96_KHZ:
  88. return DP_LINK_ENUM_STR(AUDIO_SAMPLE_RATE_96_KHZ);
  89. case AUDIO_SAMPLE_RATE_176_4_KHZ:
  90. return DP_LINK_ENUM_STR(AUDIO_SAMPLE_RATE_176_4_KHZ);
  91. case AUDIO_SAMPLE_RATE_192_KHZ:
  92. return DP_LINK_ENUM_STR(AUDIO_SAMPLE_RATE_192_KHZ);
  93. default:
  94. return "unknown";
  95. }
  96. }
  97. static int dp_link_get_period(struct dp_link_private *link, int const addr)
  98. {
  99. int ret = 0;
  100. u8 bp;
  101. u8 data;
  102. u32 const param_len = 0x1;
  103. u32 const max_audio_period = 0xA;
  104. /* TEST_AUDIO_PERIOD_CH_XX */
  105. if (drm_dp_dpcd_read(link->aux->drm_aux, addr, &bp,
  106. param_len) < param_len) {
  107. DP_ERR("failed to read test_audio_period (0x%x)\n", addr);
  108. ret = -EINVAL;
  109. goto exit;
  110. }
  111. data = bp;
  112. /* Period - Bits 3:0 */
  113. data = data & 0xF;
  114. if ((int)data > max_audio_period) {
  115. DP_ERR("invalid test_audio_period_ch_1 = 0x%x\n", data);
  116. ret = -EINVAL;
  117. goto exit;
  118. }
  119. ret = data;
  120. exit:
  121. return ret;
  122. }
  123. static int dp_link_parse_audio_channel_period(struct dp_link_private *link)
  124. {
  125. int ret = 0;
  126. struct dp_link_test_audio *req = &link->dp_link.test_audio;
  127. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH1);
  128. if (ret == -EINVAL)
  129. goto exit;
  130. req->test_audio_period_ch_1 = ret;
  131. DP_DEBUG("test_audio_period_ch_1 = 0x%x\n", ret);
  132. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH2);
  133. if (ret == -EINVAL)
  134. goto exit;
  135. req->test_audio_period_ch_2 = ret;
  136. DP_DEBUG("test_audio_period_ch_2 = 0x%x\n", ret);
  137. /* TEST_AUDIO_PERIOD_CH_3 (Byte 0x275) */
  138. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH3);
  139. if (ret == -EINVAL)
  140. goto exit;
  141. req->test_audio_period_ch_3 = ret;
  142. DP_DEBUG("test_audio_period_ch_3 = 0x%x\n", ret);
  143. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH4);
  144. if (ret == -EINVAL)
  145. goto exit;
  146. req->test_audio_period_ch_4 = ret;
  147. DP_DEBUG("test_audio_period_ch_4 = 0x%x\n", ret);
  148. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH5);
  149. if (ret == -EINVAL)
  150. goto exit;
  151. req->test_audio_period_ch_5 = ret;
  152. DP_DEBUG("test_audio_period_ch_5 = 0x%x\n", ret);
  153. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH6);
  154. if (ret == -EINVAL)
  155. goto exit;
  156. req->test_audio_period_ch_6 = ret;
  157. DP_DEBUG("test_audio_period_ch_6 = 0x%x\n", ret);
  158. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH7);
  159. if (ret == -EINVAL)
  160. goto exit;
  161. req->test_audio_period_ch_7 = ret;
  162. DP_DEBUG("test_audio_period_ch_7 = 0x%x\n", ret);
  163. ret = dp_link_get_period(link, DP_TEST_AUDIO_PERIOD_CH8);
  164. if (ret == -EINVAL)
  165. goto exit;
  166. req->test_audio_period_ch_8 = ret;
  167. DP_DEBUG("test_audio_period_ch_8 = 0x%x\n", ret);
  168. exit:
  169. return ret;
  170. }
  171. static int dp_link_parse_audio_pattern_type(struct dp_link_private *link)
  172. {
  173. int ret = 0;
  174. u8 bp;
  175. u8 data;
  176. int rlen;
  177. int const param_len = 0x1;
  178. int const max_audio_pattern_type = 0x1;
  179. rlen = drm_dp_dpcd_read(link->aux->drm_aux,
  180. DP_TEST_AUDIO_PATTERN_TYPE, &bp, param_len);
  181. if (rlen < param_len) {
  182. DP_ERR("failed to read link audio mode data\n");
  183. ret = -EINVAL;
  184. goto exit;
  185. }
  186. data = bp;
  187. /* Audio Pattern Type - Bits 7:0 */
  188. if ((int)data > max_audio_pattern_type) {
  189. DP_ERR("invalid audio pattern type = 0x%x\n", data);
  190. ret = -EINVAL;
  191. goto exit;
  192. }
  193. link->dp_link.test_audio.test_audio_pattern_type = data;
  194. DP_DEBUG("audio pattern type = %s\n",
  195. dp_link_get_audio_test_pattern(data));
  196. exit:
  197. return ret;
  198. }
  199. static int dp_link_parse_audio_mode(struct dp_link_private *link)
  200. {
  201. int ret = 0;
  202. u8 bp;
  203. u8 data;
  204. int rlen;
  205. int const param_len = 0x1;
  206. int const max_audio_sampling_rate = 0x6;
  207. int const max_audio_channel_count = 0x8;
  208. int sampling_rate = 0x0;
  209. int channel_count = 0x0;
  210. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_TEST_AUDIO_MODE,
  211. &bp, param_len);
  212. if (rlen < param_len) {
  213. DP_ERR("failed to read link audio mode data\n");
  214. ret = -EINVAL;
  215. goto exit;
  216. }
  217. data = bp;
  218. /* Sampling Rate - Bits 3:0 */
  219. sampling_rate = data & 0xF;
  220. if (sampling_rate > max_audio_sampling_rate) {
  221. DP_ERR("sampling rate (0x%x) greater than max (0x%x)\n",
  222. sampling_rate, max_audio_sampling_rate);
  223. ret = -EINVAL;
  224. goto exit;
  225. }
  226. /* Channel Count - Bits 7:4 */
  227. channel_count = ((data & 0xF0) >> 4) + 1;
  228. if (channel_count > max_audio_channel_count) {
  229. DP_ERR("channel_count (0x%x) greater than max (0x%x)\n",
  230. channel_count, max_audio_channel_count);
  231. ret = -EINVAL;
  232. goto exit;
  233. }
  234. link->dp_link.test_audio.test_audio_sampling_rate = sampling_rate;
  235. link->dp_link.test_audio.test_audio_channel_count = channel_count;
  236. DP_DEBUG("sampling_rate = %s, channel_count = 0x%x\n",
  237. dp_link_get_audio_sample_rate(sampling_rate), channel_count);
  238. exit:
  239. return ret;
  240. }
  241. /**
  242. * dp_parse_audio_pattern_params() - parses audio pattern parameters from DPCD
  243. * @link: Display Port Driver data
  244. *
  245. * Returns 0 if it successfully parses the audio link pattern parameters.
  246. */
  247. static int dp_link_parse_audio_pattern_params(struct dp_link_private *link)
  248. {
  249. int ret = 0;
  250. ret = dp_link_parse_audio_mode(link);
  251. if (ret)
  252. goto exit;
  253. ret = dp_link_parse_audio_pattern_type(link);
  254. if (ret)
  255. goto exit;
  256. ret = dp_link_parse_audio_channel_period(link);
  257. exit:
  258. return ret;
  259. }
  260. /**
  261. * dp_link_is_video_pattern_valid() - validates the video pattern
  262. * @pattern: video pattern requested by the sink
  263. *
  264. * Returns true if the requested video pattern is supported.
  265. */
  266. static bool dp_link_is_video_pattern_valid(u32 pattern)
  267. {
  268. switch (pattern) {
  269. case DP_NO_TEST_PATTERN:
  270. case DP_COLOR_RAMP:
  271. case DP_BLACK_AND_WHITE_VERTICAL_LINES:
  272. case DP_COLOR_SQUARE:
  273. return true;
  274. default:
  275. return false;
  276. }
  277. }
  278. static char *dp_link_video_pattern_to_string(u32 test_video_pattern)
  279. {
  280. switch (test_video_pattern) {
  281. case DP_NO_TEST_PATTERN:
  282. return DP_LINK_ENUM_STR(DP_NO_TEST_PATTERN);
  283. case DP_COLOR_RAMP:
  284. return DP_LINK_ENUM_STR(DP_COLOR_RAMP);
  285. case DP_BLACK_AND_WHITE_VERTICAL_LINES:
  286. return DP_LINK_ENUM_STR(DP_BLACK_AND_WHITE_VERTICAL_LINES);
  287. case DP_COLOR_SQUARE:
  288. return DP_LINK_ENUM_STR(DP_COLOR_SQUARE);
  289. default:
  290. return "unknown";
  291. }
  292. }
  293. /**
  294. * dp_link_is_dynamic_range_valid() - validates the dynamic range
  295. * @bit_depth: the dynamic range value to be checked
  296. *
  297. * Returns true if the dynamic range value is supported.
  298. */
  299. static bool dp_link_is_dynamic_range_valid(u32 dr)
  300. {
  301. switch (dr) {
  302. case DP_DYNAMIC_RANGE_RGB_VESA:
  303. case DP_DYNAMIC_RANGE_RGB_CEA:
  304. return true;
  305. default:
  306. return false;
  307. }
  308. }
  309. static char *dp_link_dynamic_range_to_string(u32 dr)
  310. {
  311. switch (dr) {
  312. case DP_DYNAMIC_RANGE_RGB_VESA:
  313. return DP_LINK_ENUM_STR(DP_DYNAMIC_RANGE_RGB_VESA);
  314. case DP_DYNAMIC_RANGE_RGB_CEA:
  315. return DP_LINK_ENUM_STR(DP_DYNAMIC_RANGE_RGB_CEA);
  316. case DP_DYNAMIC_RANGE_UNKNOWN:
  317. default:
  318. return "unknown";
  319. }
  320. }
  321. /**
  322. * dp_link_is_bit_depth_valid() - validates the bit depth requested
  323. * @bit_depth: bit depth requested by the sink
  324. *
  325. * Returns true if the requested bit depth is supported.
  326. */
  327. static bool dp_link_is_bit_depth_valid(u32 tbd)
  328. {
  329. /* DP_TEST_VIDEO_PATTERN_NONE is treated as invalid */
  330. switch (tbd) {
  331. case DP_TEST_BIT_DEPTH_6:
  332. case DP_TEST_BIT_DEPTH_8:
  333. case DP_TEST_BIT_DEPTH_10:
  334. return true;
  335. default:
  336. return false;
  337. }
  338. }
  339. static char *dp_link_bit_depth_to_string(u32 tbd)
  340. {
  341. switch (tbd) {
  342. case DP_TEST_BIT_DEPTH_6:
  343. return DP_LINK_ENUM_STR(DP_TEST_BIT_DEPTH_6);
  344. case DP_TEST_BIT_DEPTH_8:
  345. return DP_LINK_ENUM_STR(DP_TEST_BIT_DEPTH_8);
  346. case DP_TEST_BIT_DEPTH_10:
  347. return DP_LINK_ENUM_STR(DP_TEST_BIT_DEPTH_10);
  348. case DP_TEST_BIT_DEPTH_UNKNOWN:
  349. default:
  350. return "unknown";
  351. }
  352. }
  353. static int dp_link_parse_timing_params1(struct dp_link_private *link,
  354. int const addr, int const len, u32 *val)
  355. {
  356. u8 bp[2];
  357. int rlen;
  358. if (len < 2)
  359. return -EINVAL;
  360. /* Read the requested video link pattern (Byte 0x221). */
  361. rlen = drm_dp_dpcd_read(link->aux->drm_aux, addr, bp, len);
  362. if (rlen < len) {
  363. DP_ERR("failed to read 0x%x\n", addr);
  364. return -EINVAL;
  365. }
  366. *val = bp[1] | (bp[0] << 8);
  367. return 0;
  368. }
  369. static int dp_link_parse_timing_params2(struct dp_link_private *link,
  370. int const addr, int const len, u32 *val1, u32 *val2)
  371. {
  372. u8 bp[2];
  373. int rlen;
  374. if (len < 2)
  375. return -EINVAL;
  376. /* Read the requested video link pattern (Byte 0x221). */
  377. rlen = drm_dp_dpcd_read(link->aux->drm_aux, addr, bp, len);
  378. if (rlen < len) {
  379. DP_ERR("failed to read 0x%x\n", addr);
  380. return -EINVAL;
  381. }
  382. *val1 = (bp[0] & BIT(7)) >> 7;
  383. *val2 = bp[1] | ((bp[0] & 0x7F) << 8);
  384. return 0;
  385. }
  386. static int dp_link_parse_timing_params3(struct dp_link_private *link,
  387. int const addr, u32 *val)
  388. {
  389. u8 bp;
  390. u32 len = 1;
  391. int rlen;
  392. rlen = drm_dp_dpcd_read(link->aux->drm_aux, addr, &bp, len);
  393. if (rlen < 1) {
  394. DP_ERR("failed to read 0x%x\n", addr);
  395. return -EINVAL;
  396. }
  397. *val = bp;
  398. return 0;
  399. }
  400. /**
  401. * dp_parse_video_pattern_params() - parses video pattern parameters from DPCD
  402. * @link: Display Port Driver data
  403. *
  404. * Returns 0 if it successfully parses the video link pattern and the link
  405. * bit depth requested by the sink and, and if the values parsed are valid.
  406. */
  407. static int dp_link_parse_video_pattern_params(struct dp_link_private *link)
  408. {
  409. int ret = 0;
  410. int rlen;
  411. u8 bp;
  412. u8 data;
  413. u32 dyn_range;
  414. int const param_len = 0x1;
  415. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_TEST_PATTERN,
  416. &bp, param_len);
  417. if (rlen < param_len) {
  418. DP_ERR("failed to read link video pattern\n");
  419. ret = -EINVAL;
  420. goto exit;
  421. }
  422. data = bp;
  423. if (!dp_link_is_video_pattern_valid(data)) {
  424. DP_ERR("invalid link video pattern = 0x%x\n", data);
  425. ret = -EINVAL;
  426. goto exit;
  427. }
  428. link->dp_link.test_video.test_video_pattern = data;
  429. DP_DEBUG("link video pattern = 0x%x (%s)\n",
  430. link->dp_link.test_video.test_video_pattern,
  431. dp_link_video_pattern_to_string(
  432. link->dp_link.test_video.test_video_pattern));
  433. /* Read the requested color bit depth and dynamic range (Byte 0x232) */
  434. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_TEST_MISC0,
  435. &bp, param_len);
  436. if (rlen < param_len) {
  437. DP_ERR("failed to read link bit depth\n");
  438. ret = -EINVAL;
  439. goto exit;
  440. }
  441. data = bp;
  442. /* Dynamic Range */
  443. dyn_range = (data & DP_TEST_DYNAMIC_RANGE_CEA) >> 3;
  444. if (!dp_link_is_dynamic_range_valid(dyn_range)) {
  445. DP_ERR("invalid link dynamic range = 0x%x\n", dyn_range);
  446. ret = -EINVAL;
  447. goto exit;
  448. }
  449. link->dp_link.test_video.test_dyn_range = dyn_range;
  450. DP_DEBUG("link dynamic range = 0x%x (%s)\n",
  451. link->dp_link.test_video.test_dyn_range,
  452. dp_link_dynamic_range_to_string(
  453. link->dp_link.test_video.test_dyn_range));
  454. /* Color bit depth */
  455. data &= DP_TEST_BIT_DEPTH_MASK;
  456. if (!dp_link_is_bit_depth_valid(data)) {
  457. DP_ERR("invalid link bit depth = 0x%x\n", data);
  458. ret = -EINVAL;
  459. goto exit;
  460. }
  461. link->dp_link.test_video.test_bit_depth = data;
  462. DP_DEBUG("link bit depth = 0x%x (%s)\n",
  463. link->dp_link.test_video.test_bit_depth,
  464. dp_link_bit_depth_to_string(
  465. link->dp_link.test_video.test_bit_depth));
  466. /* resolution timing params */
  467. ret = dp_link_parse_timing_params1(link, DP_TEST_H_TOTAL_HI, 2,
  468. &link->dp_link.test_video.test_h_total);
  469. if (ret) {
  470. DP_ERR("failed to parse test_h_total (DP_TEST_H_TOTAL_HI)\n");
  471. goto exit;
  472. }
  473. DP_DEBUG("TEST_H_TOTAL = %d\n", link->dp_link.test_video.test_h_total);
  474. ret = dp_link_parse_timing_params1(link, DP_TEST_V_TOTAL_HI, 2,
  475. &link->dp_link.test_video.test_v_total);
  476. if (ret) {
  477. DP_ERR("failed to parse test_v_total (DP_TEST_V_TOTAL_HI)\n");
  478. goto exit;
  479. }
  480. DP_DEBUG("TEST_V_TOTAL = %d\n", link->dp_link.test_video.test_v_total);
  481. ret = dp_link_parse_timing_params1(link, DP_TEST_H_START_HI, 2,
  482. &link->dp_link.test_video.test_h_start);
  483. if (ret) {
  484. DP_ERR("failed to parse test_h_start (DP_TEST_H_START_HI)\n");
  485. goto exit;
  486. }
  487. DP_DEBUG("TEST_H_START = %d\n", link->dp_link.test_video.test_h_start);
  488. ret = dp_link_parse_timing_params1(link, DP_TEST_V_START_HI, 2,
  489. &link->dp_link.test_video.test_v_start);
  490. if (ret) {
  491. DP_ERR("failed to parse test_v_start (DP_TEST_V_START_HI)\n");
  492. goto exit;
  493. }
  494. DP_DEBUG("TEST_V_START = %d\n", link->dp_link.test_video.test_v_start);
  495. ret = dp_link_parse_timing_params2(link, DP_TEST_HSYNC_HI, 2,
  496. &link->dp_link.test_video.test_hsync_pol,
  497. &link->dp_link.test_video.test_hsync_width);
  498. if (ret) {
  499. DP_ERR("failed to parse (DP_TEST_HSYNC_HI)\n");
  500. goto exit;
  501. }
  502. DP_DEBUG("TEST_HSYNC_POL = %d\n",
  503. link->dp_link.test_video.test_hsync_pol);
  504. DP_DEBUG("TEST_HSYNC_WIDTH = %d\n",
  505. link->dp_link.test_video.test_hsync_width);
  506. ret = dp_link_parse_timing_params2(link, DP_TEST_VSYNC_HI, 2,
  507. &link->dp_link.test_video.test_vsync_pol,
  508. &link->dp_link.test_video.test_vsync_width);
  509. if (ret) {
  510. DP_ERR("failed to parse (DP_TEST_VSYNC_HI)\n");
  511. goto exit;
  512. }
  513. DP_DEBUG("TEST_VSYNC_POL = %d\n",
  514. link->dp_link.test_video.test_vsync_pol);
  515. DP_DEBUG("TEST_VSYNC_WIDTH = %d\n",
  516. link->dp_link.test_video.test_vsync_width);
  517. ret = dp_link_parse_timing_params1(link, DP_TEST_H_WIDTH_HI, 2,
  518. &link->dp_link.test_video.test_h_width);
  519. if (ret) {
  520. DP_ERR("failed to parse test_h_width (DP_TEST_H_WIDTH_HI)\n");
  521. goto exit;
  522. }
  523. DP_DEBUG("TEST_H_WIDTH = %d\n", link->dp_link.test_video.test_h_width);
  524. ret = dp_link_parse_timing_params1(link, DP_TEST_V_HEIGHT_HI, 2,
  525. &link->dp_link.test_video.test_v_height);
  526. if (ret) {
  527. DP_ERR("failed to parse test_v_height (DP_TEST_V_HEIGHT_HI)\n");
  528. goto exit;
  529. }
  530. DP_DEBUG("TEST_V_HEIGHT = %d\n",
  531. link->dp_link.test_video.test_v_height);
  532. ret = dp_link_parse_timing_params3(link, DP_TEST_MISC1,
  533. &link->dp_link.test_video.test_rr_d);
  534. link->dp_link.test_video.test_rr_d &= DP_TEST_REFRESH_DENOMINATOR;
  535. if (ret) {
  536. DP_ERR("failed to parse test_rr_d (DP_TEST_MISC1)\n");
  537. goto exit;
  538. }
  539. DP_DEBUG("TEST_REFRESH_DENOMINATOR = %d\n",
  540. link->dp_link.test_video.test_rr_d);
  541. ret = dp_link_parse_timing_params3(link, DP_TEST_REFRESH_RATE_NUMERATOR,
  542. &link->dp_link.test_video.test_rr_n);
  543. if (ret) {
  544. DP_ERR("failed to parse test_rr_n (DP_TEST_REFRESH_RATE_NUMERATOR)\n");
  545. goto exit;
  546. }
  547. DP_DEBUG("TEST_REFRESH_NUMERATOR = %d\n",
  548. link->dp_link.test_video.test_rr_n);
  549. exit:
  550. return ret;
  551. }
  552. /**
  553. * dp_link_parse_link_training_params() - parses link training parameters from
  554. * DPCD
  555. * @link: Display Port Driver data
  556. *
  557. * Returns 0 if it successfully parses the link rate (Byte 0x219) and lane
  558. * count (Byte 0x220), and if these values parse are valid.
  559. */
  560. static int dp_link_parse_link_training_params(struct dp_link_private *link)
  561. {
  562. u8 bp;
  563. u8 data;
  564. int ret = 0;
  565. int rlen;
  566. int const param_len = 0x1;
  567. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_TEST_LINK_RATE,
  568. &bp, param_len);
  569. if (rlen < param_len) {
  570. DP_ERR("failed to read link rate\n");
  571. ret = -EINVAL;
  572. goto exit;
  573. }
  574. data = bp;
  575. if (!is_link_rate_valid(data)) {
  576. DP_ERR("invalid link rate = 0x%x\n", data);
  577. ret = -EINVAL;
  578. goto exit;
  579. }
  580. link->request.test_link_rate = data;
  581. DP_DEBUG("link rate = 0x%x\n", link->request.test_link_rate);
  582. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_TEST_LANE_COUNT,
  583. &bp, param_len);
  584. if (rlen < param_len) {
  585. DP_ERR("failed to read lane count\n");
  586. ret = -EINVAL;
  587. goto exit;
  588. }
  589. data = bp;
  590. data &= 0x1F;
  591. if (!is_lane_count_valid(data)) {
  592. DP_ERR("invalid lane count = 0x%x\n", data);
  593. ret = -EINVAL;
  594. goto exit;
  595. }
  596. link->request.test_lane_count = data;
  597. DP_DEBUG("lane count = 0x%x\n", link->request.test_lane_count);
  598. exit:
  599. return ret;
  600. }
  601. static bool dp_link_is_phy_test_pattern_supported(u32 phy_test_pattern_sel)
  602. {
  603. switch (phy_test_pattern_sel) {
  604. case DP_PHY_TEST_PATTERN_NONE:
  605. case DP_PHY_TEST_PATTERN_D10_2:
  606. case DP_PHY_TEST_PATTERN_ERROR_COUNT:
  607. case DP_PHY_TEST_PATTERN_PRBS7:
  608. case DP_PHY_TEST_PATTERN_80BIT_CUSTOM:
  609. case DP_PHY_TEST_PATTERN_CP2520:
  610. case DP_PHY_TEST_PATTERN_CP2520_3:
  611. return true;
  612. default:
  613. return false;
  614. }
  615. }
  616. /**
  617. * dp_parse_phy_test_params() - parses the phy link parameters
  618. * @link: Display Port Driver data
  619. *
  620. * Parses the DPCD (Byte 0x248) for the DP PHY link pattern that is being
  621. * requested.
  622. */
  623. static int dp_link_parse_phy_test_params(struct dp_link_private *link)
  624. {
  625. u8 bp;
  626. u8 data;
  627. int rlen;
  628. int const param_len = 0x1;
  629. int ret = 0;
  630. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_PHY_TEST_PATTERN,
  631. &bp, param_len);
  632. if (rlen < param_len) {
  633. DP_ERR("failed to read phy link pattern\n");
  634. ret = -EINVAL;
  635. goto end;
  636. }
  637. data = bp;
  638. link->dp_link.phy_params.phy_test_pattern_sel = data;
  639. DP_DEBUG("phy_test_pattern_sel = %s\n",
  640. dp_link_get_phy_test_pattern(data));
  641. if (!dp_link_is_phy_test_pattern_supported(data))
  642. ret = -EINVAL;
  643. end:
  644. return ret;
  645. }
  646. /**
  647. * dp_link_is_video_audio_test_requested() - checks for audio/video link request
  648. * @link: link requested by the sink
  649. *
  650. * Returns true if the requested link is a permitted audio/video link.
  651. */
  652. static bool dp_link_is_video_audio_test_requested(u32 link)
  653. {
  654. return (link == DP_TEST_LINK_VIDEO_PATTERN) ||
  655. (link == (DP_TEST_LINK_AUDIO_PATTERN |
  656. DP_TEST_LINK_VIDEO_PATTERN)) ||
  657. (link == DP_TEST_LINK_AUDIO_PATTERN) ||
  658. (link == (DP_TEST_LINK_AUDIO_PATTERN |
  659. DP_TEST_LINK_AUDIO_DISABLED_VIDEO));
  660. }
  661. /**
  662. * dp_link_supported() - checks if link requested by sink is supported
  663. * @test_requested: link requested by the sink
  664. *
  665. * Returns true if the requested link is supported.
  666. */
  667. static bool dp_link_is_test_supported(u32 test_requested)
  668. {
  669. return (test_requested == DP_TEST_LINK_TRAINING) ||
  670. (test_requested == DP_TEST_LINK_EDID_READ) ||
  671. (test_requested == DP_TEST_LINK_PHY_TEST_PATTERN) ||
  672. dp_link_is_video_audio_test_requested(test_requested);
  673. }
  674. static bool dp_link_is_test_edid_read(struct dp_link_private *link)
  675. {
  676. return (link->request.test_requested == DP_TEST_LINK_EDID_READ);
  677. }
  678. /**
  679. * dp_sink_parse_test_request() - parses link request parameters from sink
  680. * @link: Display Port Driver data
  681. *
  682. * Parses the DPCD to check if an automated link is requested (Byte 0x201),
  683. * and what type of link automation is being requested (Byte 0x218).
  684. */
  685. static int dp_link_parse_request(struct dp_link_private *link)
  686. {
  687. int ret = 0;
  688. u8 bp;
  689. u8 data;
  690. int rlen;
  691. u32 const param_len = 0x1;
  692. /**
  693. * Read the device service IRQ vector (Byte 0x201) to determine
  694. * whether an automated link has been requested by the sink.
  695. */
  696. rlen = drm_dp_dpcd_read(link->aux->drm_aux,
  697. DP_DEVICE_SERVICE_IRQ_VECTOR, &bp, param_len);
  698. if (rlen < param_len) {
  699. DP_ERR("aux read failed\n");
  700. ret = -EINVAL;
  701. goto end;
  702. }
  703. data = bp;
  704. if (!(data & DP_AUTOMATED_TEST_REQUEST))
  705. return 0;
  706. /**
  707. * Read the link request byte (Byte 0x218) to determine what type
  708. * of automated link has been requested by the sink.
  709. */
  710. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_TEST_REQUEST,
  711. &bp, param_len);
  712. if (rlen < param_len) {
  713. DP_ERR("aux read failed\n");
  714. ret = -EINVAL;
  715. goto end;
  716. }
  717. data = bp;
  718. if (!dp_link_is_test_supported(data)) {
  719. DP_DEBUG("link 0x%x not supported\n", data);
  720. goto end;
  721. }
  722. link->request.test_requested = data;
  723. if (link->request.test_requested == DP_TEST_LINK_PHY_TEST_PATTERN) {
  724. ret = dp_link_parse_phy_test_params(link);
  725. if (ret)
  726. goto end;
  727. ret = dp_link_parse_link_training_params(link);
  728. }
  729. if (link->request.test_requested == DP_TEST_LINK_TRAINING)
  730. ret = dp_link_parse_link_training_params(link);
  731. if (dp_link_is_video_audio_test_requested(
  732. link->request.test_requested)) {
  733. ret = dp_link_parse_video_pattern_params(link);
  734. if (ret)
  735. goto end;
  736. ret = dp_link_parse_audio_pattern_params(link);
  737. }
  738. end:
  739. /**
  740. * Send a DP_TEST_ACK if all link parameters are valid, otherwise send
  741. * a DP_TEST_NAK.
  742. */
  743. if (ret) {
  744. link->dp_link.test_response = DP_TEST_NAK;
  745. } else {
  746. if (!dp_link_is_test_edid_read(link))
  747. link->dp_link.test_response = DP_TEST_ACK;
  748. else
  749. link->dp_link.test_response =
  750. DP_TEST_EDID_CHECKSUM_WRITE;
  751. }
  752. return ret;
  753. }
  754. /**
  755. * dp_link_parse_sink_count() - parses the sink count
  756. *
  757. * Parses the DPCD to check if there is an update to the sink count
  758. * (Byte 0x200), and whether all the sink devices connected have Content
  759. * Protection enabled.
  760. */
  761. static int dp_link_parse_sink_count(struct dp_link *dp_link)
  762. {
  763. int rlen;
  764. int const param_len = 0x1;
  765. struct dp_link_private *link = container_of(dp_link,
  766. struct dp_link_private, dp_link);
  767. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_SINK_COUNT,
  768. &link->dp_link.sink_count.count, param_len);
  769. if (rlen < param_len) {
  770. DP_ERR("failed to read sink count\n");
  771. return -EINVAL;
  772. }
  773. link->dp_link.sink_count.cp_ready =
  774. link->dp_link.sink_count.count & DP_SINK_CP_READY;
  775. /* BIT 7, BIT 5:0 */
  776. link->dp_link.sink_count.count =
  777. DP_GET_SINK_COUNT(link->dp_link.sink_count.count);
  778. DP_DEBUG("sink_count = 0x%x, cp_ready = 0x%x\n",
  779. link->dp_link.sink_count.count,
  780. link->dp_link.sink_count.cp_ready);
  781. return 0;
  782. }
  783. static void dp_link_parse_sink_status_field(struct dp_link_private *link)
  784. {
  785. int len = 0;
  786. link->prev_sink_count = link->dp_link.sink_count.count;
  787. dp_link_parse_sink_count(&link->dp_link);
  788. len = drm_dp_dpcd_read_link_status(link->aux->drm_aux,
  789. link->link_status);
  790. if (len < DP_LINK_STATUS_SIZE)
  791. DP_ERR("DP link status read failed\n");
  792. #if defined(CONFIG_SECDP)
  793. else
  794. DP_INFO("[202h-207h] %02x-%02x-%02x-%02x-%02x-%02x\n",
  795. link->link_status[0], link->link_status[1], link->link_status[2],
  796. link->link_status[3], link->link_status[4], link->link_status[5]);
  797. #endif
  798. dp_link_parse_request(link);
  799. }
  800. static bool dp_link_is_link_training_requested(struct dp_link_private *link)
  801. {
  802. return (link->request.test_requested == DP_TEST_LINK_TRAINING);
  803. }
  804. /**
  805. * dp_link_process_link_training_request() - processes new training requests
  806. * @link: Display Port link data
  807. *
  808. * This function will handle new link training requests that are initiated by
  809. * the sink. In particular, it will update the requested lane count and link
  810. * link rate, and then trigger the link retraining procedure.
  811. *
  812. * The function will return 0 if a link training request has been processed,
  813. * otherwise it will return -EINVAL.
  814. */
  815. static int dp_link_process_link_training_request(struct dp_link_private *link)
  816. {
  817. if (!dp_link_is_link_training_requested(link))
  818. return -EINVAL;
  819. DP_DEBUG("%s link rate = 0x%x, lane count = 0x%x\n",
  820. dp_link_get_test_name(DP_TEST_LINK_TRAINING),
  821. link->request.test_link_rate,
  822. link->request.test_lane_count);
  823. link->dp_link.link_params.lane_count = link->request.test_lane_count;
  824. link->dp_link.link_params.bw_code = link->request.test_link_rate;
  825. return 0;
  826. }
  827. static void dp_link_send_test_response(struct dp_link *dp_link)
  828. {
  829. struct dp_link_private *link = NULL;
  830. u32 const response_len = 0x1;
  831. if (!dp_link) {
  832. DP_ERR("invalid input\n");
  833. return;
  834. }
  835. link = container_of(dp_link, struct dp_link_private, dp_link);
  836. drm_dp_dpcd_write(link->aux->drm_aux, DP_TEST_RESPONSE,
  837. &dp_link->test_response, response_len);
  838. }
  839. static int dp_link_psm_config(struct dp_link *dp_link,
  840. struct drm_dp_link *link_info, bool enable)
  841. {
  842. struct dp_link_private *link = NULL;
  843. int ret = 0;
  844. if (!dp_link) {
  845. DP_ERR("invalid params\n");
  846. return -EINVAL;
  847. }
  848. link = container_of(dp_link, struct dp_link_private, dp_link);
  849. if (enable)
  850. ret = dp_link_power_down(link->aux->drm_aux, link_info);
  851. else
  852. ret = dp_link_power_up(link->aux->drm_aux, link_info);
  853. if (ret)
  854. DP_ERR("Failed to %s low power mode\n",
  855. (enable ? "enter" : "exit"));
  856. return ret;
  857. }
  858. static void dp_link_send_edid_checksum(struct dp_link *dp_link, u8 checksum)
  859. {
  860. struct dp_link_private *link = NULL;
  861. u32 const response_len = 0x1;
  862. if (!dp_link) {
  863. DP_ERR("invalid input\n");
  864. return;
  865. }
  866. link = container_of(dp_link, struct dp_link_private, dp_link);
  867. drm_dp_dpcd_write(link->aux->drm_aux, DP_TEST_EDID_CHECKSUM,
  868. &checksum, response_len);
  869. }
  870. static int dp_link_parse_vx_px(struct dp_link_private *link)
  871. {
  872. u8 bp;
  873. u8 data;
  874. int const param_len = 0x1;
  875. int ret = 0;
  876. u32 v0, p0, v1, p1, v2, p2, v3, p3;
  877. int rlen;
  878. DP_DEBUG("\n");
  879. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_ADJUST_REQUEST_LANE0_1,
  880. &bp, param_len);
  881. if (rlen < param_len) {
  882. DP_ERR("failed reading lanes 0/1\n");
  883. ret = -EINVAL;
  884. goto end;
  885. }
  886. data = bp;
  887. DP_DEBUG("lanes 0/1 (Byte 0x206): 0x%x\n", data);
  888. v0 = data & 0x3;
  889. data = data >> 2;
  890. p0 = data & 0x3;
  891. data = data >> 2;
  892. v1 = data & 0x3;
  893. data = data >> 2;
  894. p1 = data & 0x3;
  895. data = data >> 2;
  896. rlen = drm_dp_dpcd_read(link->aux->drm_aux, DP_ADJUST_REQUEST_LANE2_3,
  897. &bp, param_len);
  898. if (rlen < param_len) {
  899. DP_ERR("failed reading lanes 2/3\n");
  900. ret = -EINVAL;
  901. goto end;
  902. }
  903. data = bp;
  904. DP_DEBUG("lanes 2/3 (Byte 0x207): 0x%x\n", data);
  905. v2 = data & 0x3;
  906. data = data >> 2;
  907. p2 = data & 0x3;
  908. data = data >> 2;
  909. v3 = data & 0x3;
  910. data = data >> 2;
  911. p3 = data & 0x3;
  912. data = data >> 2;
  913. DP_DEBUG("vx: 0=%d, 1=%d, 2=%d, 3=%d\n", v0, v1, v2, v3);
  914. DP_DEBUG("px: 0=%d, 1=%d, 2=%d, 3=%d\n", p0, p1, p2, p3);
  915. /**
  916. * Update the voltage and pre-emphasis levels as per DPCD request
  917. * vector.
  918. */
  919. DP_DEBUG("Current: v_level = 0x%x, p_level = 0x%x\n",
  920. link->dp_link.phy_params.v_level,
  921. link->dp_link.phy_params.p_level);
  922. DP_DEBUG("Requested: v_level = 0x%x, p_level = 0x%x\n", v0, p0);
  923. link->dp_link.phy_params.v_level = v0;
  924. link->dp_link.phy_params.p_level = p0;
  925. DP_DEBUG("Success\n");
  926. end:
  927. return ret;
  928. }
  929. /**
  930. * dp_link_process_phy_test_pattern_request() - process new phy link requests
  931. * @link: Display Port Driver data
  932. *
  933. * This function will handle new phy link pattern requests that are initiated
  934. * by the sink. The function will return 0 if a phy link pattern has been
  935. * processed, otherwise it will return -EINVAL.
  936. */
  937. static int dp_link_process_phy_test_pattern_request(
  938. struct dp_link_private *link)
  939. {
  940. u32 test_link_rate = 0, test_lane_count = 0;
  941. if (!(link->request.test_requested & DP_TEST_LINK_PHY_TEST_PATTERN)) {
  942. DP_DEBUG("no phy test\n");
  943. return -EINVAL;
  944. }
  945. test_link_rate = link->request.test_link_rate;
  946. test_lane_count = link->request.test_lane_count;
  947. if (!is_link_rate_valid(test_link_rate) ||
  948. !is_lane_count_valid(test_lane_count)) {
  949. DP_ERR("Invalid params: link rate = 0x%x, lane count = 0x%x\n",
  950. test_link_rate, test_lane_count);
  951. return -EINVAL;
  952. }
  953. DP_DEBUG("start\n");
  954. DP_INFO("Current: bw_code = 0x%x, lane count = 0x%x\n",
  955. link->dp_link.link_params.bw_code,
  956. link->dp_link.link_params.lane_count);
  957. DP_INFO("Requested: bw_code = 0x%x, lane count = 0x%x\n",
  958. test_link_rate, test_lane_count);
  959. link->dp_link.link_params.lane_count = link->request.test_lane_count;
  960. link->dp_link.link_params.bw_code = link->request.test_link_rate;
  961. dp_link_parse_vx_px(link);
  962. DP_DEBUG("end\n");
  963. return 0;
  964. }
  965. static u8 get_link_status(const u8 link_status[DP_LINK_STATUS_SIZE], int r)
  966. {
  967. return link_status[r - DP_LANE0_1_STATUS];
  968. }
  969. /**
  970. * dp_link_process_link_status_update() - processes link status updates
  971. * @link: Display Port link module data
  972. *
  973. * This function will check for changes in the link status, e.g. clock
  974. * recovery done on all lanes, and trigger link training if there is a
  975. * failure/error on the link.
  976. *
  977. * The function will return 0 if the a link status update has been processed,
  978. * otherwise it will return -EINVAL.
  979. */
  980. static int dp_link_process_link_status_update(struct dp_link_private *link)
  981. {
  982. bool channel_eq_done = drm_dp_channel_eq_ok(link->link_status,
  983. link->dp_link.link_params.lane_count);
  984. bool clock_recovery_done = drm_dp_clock_recovery_ok(link->link_status,
  985. link->dp_link.link_params.lane_count);
  986. DP_DEBUG("channel_eq_done = %d, clock_recovery_done = %d\n",
  987. channel_eq_done, clock_recovery_done);
  988. if (channel_eq_done && clock_recovery_done)
  989. return -EINVAL;
  990. return 0;
  991. }
  992. static bool dp_link_is_ds_port_status_changed(struct dp_link_private *link)
  993. {
  994. if (get_link_status(link->link_status, DP_LANE_ALIGN_STATUS_UPDATED) &
  995. DP_DOWNSTREAM_PORT_STATUS_CHANGED) /* port status changed */
  996. return true;
  997. if (link->prev_sink_count != link->dp_link.sink_count.count)
  998. return true;
  999. return false;
  1000. }
  1001. /**
  1002. * dp_link_process_downstream_port_status_change() - process port status changes
  1003. * @link: Display Port Driver data
  1004. *
  1005. * This function will handle downstream port updates that are initiated by
  1006. * the sink. If the downstream port status has changed, the EDID is read via
  1007. * AUX.
  1008. *
  1009. * The function will return 0 if a downstream port update has been
  1010. * processed, otherwise it will return -EINVAL.
  1011. */
  1012. static int dp_link_process_ds_port_status_change(struct dp_link_private *link)
  1013. {
  1014. if (!dp_link_is_ds_port_status_changed(link))
  1015. return -EINVAL;
  1016. /* reset prev_sink_count */
  1017. link->prev_sink_count = link->dp_link.sink_count.count;
  1018. return 0;
  1019. }
  1020. static bool dp_link_is_video_pattern_requested(struct dp_link_private *link)
  1021. {
  1022. return (link->request.test_requested & DP_TEST_LINK_VIDEO_PATTERN)
  1023. && !(link->request.test_requested &
  1024. DP_TEST_LINK_AUDIO_DISABLED_VIDEO);
  1025. }
  1026. static bool dp_link_is_audio_pattern_requested(struct dp_link_private *link)
  1027. {
  1028. return (link->request.test_requested & DP_TEST_LINK_AUDIO_PATTERN);
  1029. }
  1030. /**
  1031. * dp_link_process_video_pattern_request() - process new video pattern request
  1032. * @link: Display Port link module's data
  1033. *
  1034. * This function will handle a new video pattern request that are initiated by
  1035. * the sink. This is acheieved by first sending a disconnect notification to
  1036. * the sink followed by a subsequent connect notification to the user modules,
  1037. * where it is expected that the user modules would draw the required link
  1038. * pattern.
  1039. */
  1040. static int dp_link_process_video_pattern_request(struct dp_link_private *link)
  1041. {
  1042. if (!dp_link_is_video_pattern_requested(link))
  1043. goto end;
  1044. DP_DEBUG("%s: bit depth=%d(%d bpp) pattern=%s\n",
  1045. dp_link_get_test_name(DP_TEST_LINK_VIDEO_PATTERN),
  1046. link->dp_link.test_video.test_bit_depth,
  1047. dp_link_bit_depth_to_bpp(
  1048. link->dp_link.test_video.test_bit_depth),
  1049. dp_link_video_pattern_to_string(
  1050. link->dp_link.test_video.test_video_pattern));
  1051. return 0;
  1052. end:
  1053. return -EINVAL;
  1054. }
  1055. /**
  1056. * dp_link_process_audio_pattern_request() - process new audio pattern request
  1057. * @link: Display Port link module data
  1058. *
  1059. * This function will handle a new audio pattern request that is initiated by
  1060. * the sink. This is acheieved by sending the necessary secondary data packets
  1061. * to the sink. It is expected that any simulatenous requests for video
  1062. * patterns will be handled before the audio pattern is sent to the sink.
  1063. */
  1064. static int dp_link_process_audio_pattern_request(struct dp_link_private *link)
  1065. {
  1066. if (!dp_link_is_audio_pattern_requested(link))
  1067. return -EINVAL;
  1068. DP_DEBUG("sampling_rate=%s, channel_count=%d, pattern_type=%s\n",
  1069. dp_link_get_audio_sample_rate(
  1070. link->dp_link.test_audio.test_audio_sampling_rate),
  1071. link->dp_link.test_audio.test_audio_channel_count,
  1072. dp_link_get_audio_test_pattern(
  1073. link->dp_link.test_audio.test_audio_pattern_type));
  1074. DP_DEBUG("audio_period: ch1=0x%x, ch2=0x%x, ch3=0x%x, ch4=0x%x\n",
  1075. link->dp_link.test_audio.test_audio_period_ch_1,
  1076. link->dp_link.test_audio.test_audio_period_ch_2,
  1077. link->dp_link.test_audio.test_audio_period_ch_3,
  1078. link->dp_link.test_audio.test_audio_period_ch_4);
  1079. DP_DEBUG("audio_period: ch5=0x%x, ch6=0x%x, ch7=0x%x, ch8=0x%x\n",
  1080. link->dp_link.test_audio.test_audio_period_ch_5,
  1081. link->dp_link.test_audio.test_audio_period_ch_6,
  1082. link->dp_link.test_audio.test_audio_period_ch_7,
  1083. link->dp_link.test_audio.test_audio_period_ch_8);
  1084. return 0;
  1085. }
  1086. static void dp_link_reset_data(struct dp_link_private *link)
  1087. {
  1088. link->request = (const struct dp_link_request){ 0 };
  1089. link->dp_link.test_video = (const struct dp_link_test_video){ 0 };
  1090. link->dp_link.test_video.test_bit_depth = DP_TEST_BIT_DEPTH_UNKNOWN;
  1091. link->dp_link.test_audio = (const struct dp_link_test_audio){ 0 };
  1092. link->dp_link.phy_params.phy_test_pattern_sel = 0;
  1093. link->dp_link.sink_request = 0;
  1094. link->dp_link.test_response = 0;
  1095. }
  1096. #if defined(CONFIG_SECDP)
  1097. bool secdp_get_poor_connection_status(struct dp_link *dp_link)
  1098. {
  1099. return dp_link->poor_connection;
  1100. }
  1101. void secdp_clear_link_status_cnt(struct dp_link *dp_link)
  1102. {
  1103. dp_link->poor_connection = false;
  1104. dp_link->status_update_cnt = 0;
  1105. }
  1106. /** refer to dp_link_parse_sink_status_field() */
  1107. void secdp_read_link_status(struct dp_link *dp_link)
  1108. {
  1109. struct dp_link_private *link;
  1110. int len = 0;
  1111. if (!dp_link) {
  1112. DP_ERR("invalid input\n");
  1113. goto exit;
  1114. }
  1115. link = container_of(dp_link, struct dp_link_private, dp_link);
  1116. if (!link) {
  1117. DP_ERR("link is null\n");
  1118. goto exit;
  1119. }
  1120. DP_ENTER("\n");
  1121. len = drm_dp_dpcd_read_link_status(link->aux->drm_aux,
  1122. link->link_status);
  1123. if (len < DP_LINK_STATUS_SIZE) {
  1124. DP_ERR("DP link status read failed %d\n", len);
  1125. goto exit;
  1126. }
  1127. DP_INFO("[202h-207h] %02x-%02x-%02x-%02x-%02x-%02x\n",
  1128. link->link_status[0], link->link_status[1], link->link_status[2],
  1129. link->link_status[3], link->link_status[4], link->link_status[5]);
  1130. exit:
  1131. return;
  1132. }
  1133. /**
  1134. * @retval true if connection is stable
  1135. * @retval false if connection is unstable(poor)
  1136. */
  1137. bool secdp_check_link_stable(struct dp_link *dp_link)
  1138. {
  1139. bool stable = false;
  1140. struct dp_link_private *link;
  1141. if (!dp_link) {
  1142. DP_ERR("invalid input\n");
  1143. goto exit;
  1144. }
  1145. link = container_of(dp_link, struct dp_link_private, dp_link);
  1146. if (!link) {
  1147. DP_ERR("link is null\n");
  1148. goto exit;
  1149. }
  1150. if (!(get_link_status(link->link_status, DP_LANE_ALIGN_STATUS_UPDATED) &
  1151. DP_INTERLANE_ALIGN_DONE)) {
  1152. DP_ERR("[204h] interlane_align_done is zero!\n");
  1153. goto exit;
  1154. }
  1155. stable = true;
  1156. exit:
  1157. if (stable)
  1158. DP_DEBUG("DP connection is stable!\n");
  1159. #if defined(CONFIG_SECDP_BIGDATA)
  1160. if (!stable)
  1161. secdp_bigdata_inc_error_cnt(ERR_INF_IRQHPD);
  1162. #endif
  1163. return stable;
  1164. }
  1165. #if defined(CONFIG_SECDP_DBG)
  1166. int secdp_show_link_param(struct dp_link *dp_link, char *buf)
  1167. {
  1168. int rc = 0;
  1169. rc += scnprintf(buf + rc, PAGE_SIZE - rc,
  1170. "v_level: %u\np_level: %u\nlane_cnt: %u\nbw_code: 0x%x\n",
  1171. dp_link->phy_params.v_level,
  1172. dp_link->phy_params.p_level,
  1173. dp_link->link_params.lane_count,
  1174. dp_link->link_params.bw_code);
  1175. return rc;
  1176. }
  1177. #endif/*CONFIG_SECDP_DBG*/
  1178. #endif/*CONFIG_SECDP*/
  1179. /**
  1180. * dp_link_process_request() - handle HPD IRQ transition to HIGH
  1181. * @link: pointer to link module data
  1182. *
  1183. * This function will handle the HPD IRQ state transitions from LOW to HIGH
  1184. * (including cases when there are back to back HPD IRQ HIGH) indicating
  1185. * the start of a new link training request or sink status update.
  1186. */
  1187. static int dp_link_process_request(struct dp_link *dp_link)
  1188. {
  1189. int ret = 0;
  1190. struct dp_link_private *link;
  1191. if (!dp_link) {
  1192. DP_ERR("invalid input\n");
  1193. return -EINVAL;
  1194. }
  1195. link = container_of(dp_link, struct dp_link_private, dp_link);
  1196. dp_link_reset_data(link);
  1197. dp_link_parse_sink_status_field(link);
  1198. #if defined(CONFIG_SECDP)
  1199. if (secdp_get_power_status() && !secdp_check_link_stable(dp_link)) {
  1200. dp_link->status_update_cnt++;
  1201. DP_INFO("[link_request] status_update_cnt %d\n",
  1202. dp_link->status_update_cnt);
  1203. secdp_link_backoff_start();
  1204. }
  1205. #endif
  1206. if (dp_link_is_test_edid_read(link)) {
  1207. dp_link->sink_request |= DP_TEST_LINK_EDID_READ;
  1208. goto exit;
  1209. }
  1210. ret = dp_link_process_ds_port_status_change(link);
  1211. if (!ret) {
  1212. dp_link->sink_request |= DS_PORT_STATUS_CHANGED;
  1213. goto exit;
  1214. }
  1215. ret = dp_link_process_link_training_request(link);
  1216. if (!ret) {
  1217. dp_link->sink_request |= DP_TEST_LINK_TRAINING;
  1218. goto exit;
  1219. }
  1220. ret = dp_link_process_phy_test_pattern_request(link);
  1221. if (!ret) {
  1222. dp_link->sink_request |= DP_TEST_LINK_PHY_TEST_PATTERN;
  1223. goto exit;
  1224. }
  1225. ret = dp_link_process_link_status_update(link);
  1226. if (!ret) {
  1227. dp_link->sink_request |= DP_LINK_STATUS_UPDATED;
  1228. goto exit;
  1229. }
  1230. ret = dp_link_process_video_pattern_request(link);
  1231. if (!ret) {
  1232. dp_link->sink_request |= DP_TEST_LINK_VIDEO_PATTERN;
  1233. goto exit;
  1234. }
  1235. ret = dp_link_process_audio_pattern_request(link);
  1236. if (!ret) {
  1237. dp_link->sink_request |= DP_TEST_LINK_AUDIO_PATTERN;
  1238. goto exit;
  1239. }
  1240. DP_DEBUG("no test requested\n");
  1241. return ret;
  1242. exit:
  1243. /*
  1244. * log this as it can be a use initiated action to run a DP CTS
  1245. * test or in normal cases, sink has encountered a problem and
  1246. * and want source to redo some part of initialization which can
  1247. * be helpful in debugging.
  1248. */
  1249. DP_INFO("event: %s\n",
  1250. dp_link_get_test_name(dp_link->sink_request));
  1251. return 0;
  1252. }
  1253. static int dp_link_get_colorimetry_config(struct dp_link *dp_link)
  1254. {
  1255. u32 cc;
  1256. enum dynamic_range dr;
  1257. struct dp_link_private *link;
  1258. if (!dp_link) {
  1259. DP_ERR("invalid input\n");
  1260. return -EINVAL;
  1261. }
  1262. link = container_of(dp_link, struct dp_link_private, dp_link);
  1263. /* unless a video pattern CTS test is ongoing, use CEA_VESA */
  1264. if (dp_link_is_video_pattern_requested(link))
  1265. dr = link->dp_link.test_video.test_dyn_range;
  1266. else
  1267. dr = DP_DYNAMIC_RANGE_RGB_VESA;
  1268. /* Only RGB_VESA nd RGB_CEA supported for now */
  1269. switch (dr) {
  1270. case DP_DYNAMIC_RANGE_RGB_CEA:
  1271. cc = BIT(2);
  1272. break;
  1273. case DP_DYNAMIC_RANGE_RGB_VESA:
  1274. default:
  1275. cc = 0;
  1276. }
  1277. return cc;
  1278. }
  1279. static int dp_link_adjust_levels(struct dp_link *dp_link, u8 *link_status)
  1280. {
  1281. int i;
  1282. int max = 0;
  1283. u8 data;
  1284. struct dp_link_private *link;
  1285. u8 buf[8] = {0}, offset = 0;
  1286. if (!dp_link) {
  1287. DP_ERR("invalid input\n");
  1288. return -EINVAL;
  1289. }
  1290. link = container_of(dp_link, struct dp_link_private, dp_link);
  1291. /* use the max level across lanes */
  1292. for (i = 0; i < dp_link->link_params.lane_count; i++) {
  1293. data = drm_dp_get_adjust_request_voltage(link_status, i);
  1294. data >>= DP_TRAIN_VOLTAGE_SWING_SHIFT;
  1295. offset = i * 2;
  1296. if (offset < sizeof(buf))
  1297. buf[offset] = data;
  1298. if (max < data)
  1299. max = data;
  1300. }
  1301. dp_link->phy_params.v_level = max;
  1302. /* use the max level across lanes */
  1303. max = 0;
  1304. for (i = 0; i < dp_link->link_params.lane_count; i++) {
  1305. data = drm_dp_get_adjust_request_pre_emphasis(link_status, i);
  1306. data >>= DP_TRAIN_PRE_EMPHASIS_SHIFT;
  1307. offset = (i * 2) + 1;
  1308. if (offset < sizeof(buf))
  1309. buf[offset] = data;
  1310. if (max < data)
  1311. max = data;
  1312. }
  1313. dp_link->phy_params.p_level = max;
  1314. print_hex_dump_debug("[drm-dp] Req (VxPx): ",
  1315. DUMP_PREFIX_NONE, 8, 2, buf, sizeof(buf), false);
  1316. DP_DEBUG("Current (VxPx): 0x%x, 0x%x\n",
  1317. dp_link->phy_params.v_level, dp_link->phy_params.p_level);
  1318. /**
  1319. * Adjust the voltage swing and pre-emphasis level combination to within
  1320. * the allowable range.
  1321. */
  1322. if (dp_link->phy_params.v_level > dp_link->phy_params.max_v_level)
  1323. dp_link->phy_params.v_level = dp_link->phy_params.max_v_level;
  1324. if (dp_link->phy_params.p_level > dp_link->phy_params.max_p_level)
  1325. dp_link->phy_params.p_level = dp_link->phy_params.max_p_level;
  1326. if ((dp_link->phy_params.p_level > DP_LINK_PRE_EMPHASIS_LEVEL_1)
  1327. && (dp_link->phy_params.v_level == DP_LINK_VOLTAGE_LEVEL_2))
  1328. dp_link->phy_params.p_level = DP_LINK_PRE_EMPHASIS_LEVEL_1;
  1329. if ((dp_link->phy_params.p_level > DP_LINK_PRE_EMPHASIS_LEVEL_2)
  1330. && (dp_link->phy_params.v_level == DP_LINK_VOLTAGE_LEVEL_1))
  1331. dp_link->phy_params.p_level = DP_LINK_PRE_EMPHASIS_LEVEL_2;
  1332. DP_DEBUG("Set (VxPx): 0x%x, 0x%x\n",
  1333. dp_link->phy_params.v_level, dp_link->phy_params.p_level);
  1334. return 0;
  1335. }
  1336. static int dp_link_send_psm_request(struct dp_link *dp_link, bool req)
  1337. {
  1338. struct dp_link_private *link;
  1339. if (!dp_link) {
  1340. DP_ERR("invalid input\n");
  1341. return -EINVAL;
  1342. }
  1343. link = container_of(dp_link, struct dp_link_private, dp_link);
  1344. return 0;
  1345. }
  1346. static u32 dp_link_get_test_bits_depth(struct dp_link *dp_link, u32 bpp)
  1347. {
  1348. u32 tbd;
  1349. /*
  1350. * Few simplistic rules and assumptions made here:
  1351. * 1. Test bit depth is bit depth per color component
  1352. * 2. Assume 3 color components
  1353. */
  1354. switch (bpp) {
  1355. case 18:
  1356. tbd = DP_TEST_BIT_DEPTH_6;
  1357. break;
  1358. case 24:
  1359. tbd = DP_TEST_BIT_DEPTH_8;
  1360. break;
  1361. case 30:
  1362. tbd = DP_TEST_BIT_DEPTH_10;
  1363. break;
  1364. default:
  1365. tbd = DP_TEST_BIT_DEPTH_UNKNOWN;
  1366. break;
  1367. }
  1368. if (tbd != DP_TEST_BIT_DEPTH_UNKNOWN)
  1369. tbd = (tbd >> DP_TEST_BIT_DEPTH_SHIFT);
  1370. return tbd;
  1371. }
  1372. /**
  1373. * dp_link_probe() - probe a DisplayPort link for capabilities
  1374. * @aux: DisplayPort AUX channel
  1375. * @link: pointer to structure in which to return link capabilities
  1376. *
  1377. * The structure filled in by this function can usually be passed directly
  1378. * into dp_link_power_up() and dp_link_configure() to power up and
  1379. * configure the link based on the link's capabilities.
  1380. *
  1381. * Returns 0 on success or a negative error code on failure.
  1382. */
  1383. int dp_link_probe(struct drm_dp_aux *aux, struct drm_dp_link *link)
  1384. {
  1385. u8 values[3];
  1386. int ret;
  1387. memset(link, 0, sizeof(*link));
  1388. ret = drm_dp_dpcd_read(aux, DP_DPCD_REV, values, sizeof(values));
  1389. if (ret < 3) {
  1390. DP_ERR("failed to probe link, ret:%d\n", ret);
  1391. ret = -EIO;
  1392. }
  1393. link->revision = values[0];
  1394. link->rate = drm_dp_bw_code_to_link_rate(values[1]);
  1395. link->num_lanes = values[2] & DP_MAX_LANE_COUNT_MASK;
  1396. if (values[2] & DP_ENHANCED_FRAME_CAP)
  1397. link->capabilities |= DP_LINK_CAP_ENHANCED_FRAMING;
  1398. return 0;
  1399. }
  1400. /**
  1401. * dp_link_power_up() - power up a DisplayPort link
  1402. * @aux: DisplayPort AUX channel
  1403. * @link: pointer to a structure containing the link configuration
  1404. *
  1405. * Returns 0 on success or a negative error code on failure.
  1406. */
  1407. int dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link)
  1408. {
  1409. u8 value;
  1410. int ret;
  1411. /* DP_SET_POWER register is only available on DPCD v1.1 and later */
  1412. if (link->revision < 0x11)
  1413. return 0;
  1414. ret = drm_dp_dpcd_readb(aux, DP_SET_POWER, &value);
  1415. if (ret != 1) {
  1416. DP_ERR("failed to read sink power when powering up, ret:%d\n", ret);
  1417. return -EIO;
  1418. }
  1419. value &= ~DP_SET_POWER_MASK;
  1420. value |= DP_SET_POWER_D0;
  1421. ret = drm_dp_dpcd_writeb(aux, DP_SET_POWER, value);
  1422. if (ret != 1) {
  1423. DP_ERR("failed to power up[0x%x] sink, ret:%d\n", value, ret);
  1424. return -EIO;
  1425. }
  1426. /*
  1427. * According to the DP 1.1 specification, a "Sink Device must exit the
  1428. * power saving state within 1 ms" (Section 2.5.3.1, Table 5-52, "Sink
  1429. * Control Field" (register 0x600).
  1430. */
  1431. usleep_range(1000, 2000);
  1432. return 0;
  1433. }
  1434. /**
  1435. * dp_link_power_down() - power down a DisplayPort link
  1436. * @aux: DisplayPort AUX channel
  1437. * @link: pointer to a structure containing the link configuration
  1438. *
  1439. * Returns 0 on success or a negative error code on failure.
  1440. */
  1441. int dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link)
  1442. {
  1443. u8 value;
  1444. int ret;
  1445. /* DP_SET_POWER register is only available on DPCD v1.1 and later */
  1446. if (link->revision < 0x11)
  1447. return 0;
  1448. ret = drm_dp_dpcd_readb(aux, DP_SET_POWER, &value);
  1449. if (ret != 1) {
  1450. DP_ERR("failed to read sink power when powering down, ret:%d\n", ret);
  1451. return -EIO;
  1452. }
  1453. value &= ~DP_SET_POWER_MASK;
  1454. value |= DP_SET_POWER_D3;
  1455. ret = drm_dp_dpcd_writeb(aux, DP_SET_POWER, value);
  1456. if (ret != 1) {
  1457. DP_ERR("failed to power down[0x%x] sink, ret:%d\n", value, ret);
  1458. return -EIO;
  1459. }
  1460. return 0;
  1461. }
  1462. /**
  1463. * dp_link_configure() - configure a DisplayPort link
  1464. * @aux: DisplayPort AUX channel
  1465. * @link: pointer to a structure containing the link configuration
  1466. *
  1467. * Returns 0 on success or a negative error code on failure.
  1468. */
  1469. int dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link)
  1470. {
  1471. u8 values[2];
  1472. int ret;
  1473. values[0] = drm_dp_link_rate_to_bw_code(link->rate);
  1474. values[1] = link->num_lanes;
  1475. if (link->capabilities & DP_LINK_CAP_ENHANCED_FRAMING)
  1476. values[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
  1477. ret = drm_dp_dpcd_write(aux, DP_LINK_BW_SET, values, sizeof(values));
  1478. if (ret != 2) {
  1479. DP_ERR("failed to configure link, ret:%d\n", ret);
  1480. return -EIO;
  1481. }
  1482. return 0;
  1483. }
  1484. struct dp_link *dp_link_get(struct device *dev, struct dp_aux *aux, u32 dp_core_revision)
  1485. {
  1486. int rc = 0;
  1487. struct dp_link_private *link;
  1488. struct dp_link *dp_link;
  1489. if (!dev || !aux) {
  1490. DP_ERR("invalid input\n");
  1491. rc = -EINVAL;
  1492. goto error;
  1493. }
  1494. link = devm_kzalloc(dev, sizeof(*link), GFP_KERNEL);
  1495. if (!link) {
  1496. rc = -EINVAL;
  1497. goto error;
  1498. }
  1499. link->dev = dev;
  1500. link->aux = aux;
  1501. dp_link = &link->dp_link;
  1502. if (dp_core_revision >= 0x10020003)
  1503. dp_link->phy_params.max_v_level = DP_LINK_VOLTAGE_LEVEL_3;
  1504. else
  1505. dp_link->phy_params.max_v_level = DP_LINK_VOLTAGE_LEVEL_2;
  1506. dp_link->phy_params.max_p_level = DP_LINK_PRE_EMPHASIS_LEVEL_3;
  1507. dp_link->process_request = dp_link_process_request;
  1508. dp_link->get_test_bits_depth = dp_link_get_test_bits_depth;
  1509. dp_link->get_colorimetry_config = dp_link_get_colorimetry_config;
  1510. dp_link->adjust_levels = dp_link_adjust_levels;
  1511. dp_link->send_psm_request = dp_link_send_psm_request;
  1512. dp_link->send_test_response = dp_link_send_test_response;
  1513. dp_link->psm_config = dp_link_psm_config;
  1514. dp_link->send_edid_checksum = dp_link_send_edid_checksum;
  1515. return dp_link;
  1516. error:
  1517. return ERR_PTR(rc);
  1518. }
  1519. void dp_link_put(struct dp_link *dp_link)
  1520. {
  1521. struct dp_link_private *link;
  1522. if (!dp_link)
  1523. return;
  1524. link = container_of(dp_link, struct dp_link_private, dp_link);
  1525. devm_kfree(link->dev, link);
  1526. }