dp_debug.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "[drm-dp] %s: " fmt, __func__
  6. #include <linux/debugfs.h>
  7. #include <linux/slab.h>
  8. #include "dp_power.h"
  9. #include "dp_catalog.h"
  10. #include "dp_aux.h"
  11. #include "dp_debug.h"
  12. #include "drm_connector.h"
  13. #include "sde_connector.h"
  14. #include "dp_display.h"
  15. #define DEBUG_NAME "drm_dp"
  16. struct dp_debug_private {
  17. struct dentry *root;
  18. u8 *edid;
  19. u32 edid_size;
  20. u8 *dpcd;
  21. u32 dpcd_size;
  22. u32 mst_con_id;
  23. char exe_mode[SZ_32];
  24. char reg_dump[SZ_32];
  25. struct dp_hpd *hpd;
  26. struct dp_link *link;
  27. struct dp_panel *panel;
  28. struct dp_aux *aux;
  29. struct dp_catalog *catalog;
  30. struct drm_connector **connector;
  31. struct device *dev;
  32. struct dp_debug dp_debug;
  33. struct dp_parser *parser;
  34. struct dp_ctrl *ctrl;
  35. struct mutex lock;
  36. };
  37. static int dp_debug_get_edid_buf(struct dp_debug_private *debug)
  38. {
  39. int rc = 0;
  40. if (!debug->edid) {
  41. debug->edid = devm_kzalloc(debug->dev, SZ_256, GFP_KERNEL);
  42. if (!debug->edid) {
  43. rc = -ENOMEM;
  44. goto end;
  45. }
  46. debug->edid_size = SZ_256;
  47. }
  48. end:
  49. return rc;
  50. }
  51. static int dp_debug_get_dpcd_buf(struct dp_debug_private *debug)
  52. {
  53. int rc = 0;
  54. if (!debug->dpcd) {
  55. debug->dpcd = devm_kzalloc(debug->dev, SZ_4K, GFP_KERNEL);
  56. if (!debug->dpcd) {
  57. rc = -ENOMEM;
  58. goto end;
  59. }
  60. debug->dpcd_size = SZ_4K;
  61. }
  62. end:
  63. return rc;
  64. }
  65. static ssize_t dp_debug_write_edid(struct file *file,
  66. const char __user *user_buff, size_t count, loff_t *ppos)
  67. {
  68. struct dp_debug_private *debug = file->private_data;
  69. u8 *buf = NULL, *buf_t = NULL, *edid = NULL;
  70. const int char_to_nib = 2;
  71. size_t edid_size = 0;
  72. size_t size = 0, edid_buf_index = 0;
  73. ssize_t rc = count;
  74. if (!debug)
  75. return -ENODEV;
  76. mutex_lock(&debug->lock);
  77. if (*ppos)
  78. goto bail;
  79. size = min_t(size_t, count, SZ_1K);
  80. buf = kzalloc(size, GFP_KERNEL);
  81. if (ZERO_OR_NULL_PTR(buf)) {
  82. rc = -ENOMEM;
  83. goto bail;
  84. }
  85. if (copy_from_user(buf, user_buff, size))
  86. goto bail;
  87. edid_size = size / char_to_nib;
  88. buf_t = buf;
  89. if (dp_debug_get_edid_buf(debug))
  90. goto bail;
  91. if (edid_size != debug->edid_size) {
  92. pr_debug("realloc debug edid\n");
  93. if (debug->edid) {
  94. devm_kfree(debug->dev, debug->edid);
  95. debug->edid = devm_kzalloc(debug->dev,
  96. edid_size, GFP_KERNEL);
  97. if (!debug->edid) {
  98. rc = -ENOMEM;
  99. goto bail;
  100. }
  101. debug->edid_size = edid_size;
  102. debug->aux->set_sim_mode(debug->aux,
  103. debug->dp_debug.sim_mode,
  104. debug->edid, debug->dpcd);
  105. }
  106. }
  107. while (edid_size--) {
  108. char t[3];
  109. int d;
  110. memcpy(t, buf_t, sizeof(char) * char_to_nib);
  111. t[char_to_nib] = '\0';
  112. if (kstrtoint(t, 16, &d)) {
  113. pr_err("kstrtoint error\n");
  114. goto bail;
  115. }
  116. if (debug->edid && (edid_buf_index < debug->edid_size))
  117. debug->edid[edid_buf_index++] = d;
  118. buf_t += char_to_nib;
  119. }
  120. edid = debug->edid;
  121. bail:
  122. kfree(buf);
  123. debug->panel->set_edid(debug->panel, edid);
  124. /*
  125. * print edid status as this code is executed
  126. * only while running in debug mode which is manually
  127. * triggered by a tester or a script.
  128. */
  129. pr_info("[%s]\n", edid ? "SET" : "CLEAR");
  130. mutex_unlock(&debug->lock);
  131. return rc;
  132. }
  133. static ssize_t dp_debug_write_dpcd(struct file *file,
  134. const char __user *user_buff, size_t count, loff_t *ppos)
  135. {
  136. struct dp_debug_private *debug = file->private_data;
  137. u8 *buf = NULL, *buf_t = NULL, *dpcd = NULL;
  138. const int char_to_nib = 2;
  139. size_t dpcd_size = 0;
  140. size_t size = 0, dpcd_buf_index = 0;
  141. ssize_t rc = count;
  142. char offset_ch[5];
  143. u32 offset, data_len;
  144. const u32 dp_receiver_cap_size = 16;
  145. if (!debug)
  146. return -ENODEV;
  147. mutex_lock(&debug->lock);
  148. if (*ppos)
  149. goto bail;
  150. size = min_t(size_t, count, SZ_2K);
  151. if (size <= char_to_nib)
  152. goto bail;
  153. buf = kzalloc(size, GFP_KERNEL);
  154. if (ZERO_OR_NULL_PTR(buf)) {
  155. rc = -ENOMEM;
  156. goto bail;
  157. }
  158. if (copy_from_user(buf, user_buff, size))
  159. goto bail;
  160. memcpy(offset_ch, buf, 4);
  161. offset_ch[4] = '\0';
  162. if (kstrtoint(offset_ch, 16, &offset)) {
  163. pr_err("offset kstrtoint error\n");
  164. goto bail;
  165. }
  166. if (dp_debug_get_dpcd_buf(debug))
  167. goto bail;
  168. if (offset == 0xFFFF) {
  169. pr_err("clearing dpcd\n");
  170. memset(debug->dpcd, 0, debug->dpcd_size);
  171. goto bail;
  172. }
  173. size -= 4;
  174. dpcd_size = size / char_to_nib;
  175. data_len = dpcd_size;
  176. buf_t = buf + 4;
  177. dpcd_buf_index = offset;
  178. while (dpcd_size--) {
  179. char t[3];
  180. int d;
  181. memcpy(t, buf_t, sizeof(char) * char_to_nib);
  182. t[char_to_nib] = '\0';
  183. if (kstrtoint(t, 16, &d)) {
  184. pr_err("kstrtoint error\n");
  185. goto bail;
  186. }
  187. if (dpcd_buf_index < debug->dpcd_size)
  188. debug->dpcd[dpcd_buf_index++] = d;
  189. buf_t += char_to_nib;
  190. }
  191. dpcd = debug->dpcd;
  192. bail:
  193. kfree(buf);
  194. /*
  195. * Reset panel's dpcd in case of any failure. Also, set the
  196. * panel's dpcd only if a full dpcd is provided with offset as 0.
  197. */
  198. if (!dpcd || (!offset && (data_len == dp_receiver_cap_size))) {
  199. debug->panel->set_dpcd(debug->panel, dpcd);
  200. /*
  201. * print dpcd status as this code is executed
  202. * only while running in debug mode which is manually
  203. * triggered by a tester or a script.
  204. */
  205. pr_info("[%s]\n", dpcd ? "SET" : "CLEAR");
  206. } else
  207. debug->aux->dpcd_updated(debug->aux);
  208. mutex_unlock(&debug->lock);
  209. return rc;
  210. }
  211. static ssize_t dp_debug_read_dpcd(struct file *file,
  212. char __user *user_buff, size_t count, loff_t *ppos)
  213. {
  214. struct dp_debug_private *debug = file->private_data;
  215. char *buf;
  216. int const buf_size = SZ_4K;
  217. u32 offset = 0;
  218. u32 len = 0;
  219. if (!debug || !debug->aux || !debug->dpcd)
  220. return -ENODEV;
  221. if (*ppos)
  222. return 0;
  223. buf = kzalloc(buf_size, GFP_KERNEL);
  224. if (!buf)
  225. return -ENOMEM;
  226. len += snprintf(buf, buf_size, "0x%x", debug->aux->reg);
  227. if (!debug->aux->read) {
  228. while (1) {
  229. if (debug->aux->reg + offset >= buf_size ||
  230. offset >= debug->aux->size)
  231. break;
  232. len += snprintf(buf + len, buf_size - len, "0x%x",
  233. debug->dpcd[debug->aux->reg + offset++]);
  234. }
  235. if (debug->dp_debug.sim_mode && debug->aux->dpcd_updated)
  236. debug->aux->dpcd_updated(debug->aux);
  237. }
  238. if (!copy_to_user(user_buff, buf, len))
  239. *ppos += len;
  240. kfree(buf);
  241. return len;
  242. }
  243. static ssize_t dp_debug_write_hpd(struct file *file,
  244. const char __user *user_buff, size_t count, loff_t *ppos)
  245. {
  246. struct dp_debug_private *debug = file->private_data;
  247. char buf[SZ_8];
  248. size_t len = 0;
  249. int const hpd_data_mask = 0x7;
  250. int hpd = 0;
  251. if (!debug)
  252. return -ENODEV;
  253. if (*ppos)
  254. return 0;
  255. /* Leave room for termination char */
  256. len = min_t(size_t, count, SZ_8 - 1);
  257. if (copy_from_user(buf, user_buff, len))
  258. goto end;
  259. buf[len] = '\0';
  260. if (kstrtoint(buf, 10, &hpd) != 0)
  261. goto end;
  262. hpd &= hpd_data_mask;
  263. debug->dp_debug.psm_enabled = !!(hpd & BIT(1));
  264. debug->hpd->simulate_connect(debug->hpd, !!(hpd & BIT(0)));
  265. end:
  266. return len;
  267. }
  268. static ssize_t dp_debug_write_edid_modes(struct file *file,
  269. const char __user *user_buff, size_t count, loff_t *ppos)
  270. {
  271. struct dp_debug_private *debug = file->private_data;
  272. char buf[SZ_32];
  273. size_t len = 0;
  274. int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio;
  275. if (!debug)
  276. return -ENODEV;
  277. if (*ppos)
  278. goto end;
  279. /* Leave room for termination char */
  280. len = min_t(size_t, count, SZ_32 - 1);
  281. if (copy_from_user(buf, user_buff, len))
  282. goto clear;
  283. buf[len] = '\0';
  284. if (sscanf(buf, "%d %d %d %d", &hdisplay, &vdisplay, &vrefresh,
  285. &aspect_ratio) != 4)
  286. goto clear;
  287. if (!hdisplay || !vdisplay || !vrefresh)
  288. goto clear;
  289. debug->dp_debug.debug_en = true;
  290. debug->dp_debug.hdisplay = hdisplay;
  291. debug->dp_debug.vdisplay = vdisplay;
  292. debug->dp_debug.vrefresh = vrefresh;
  293. debug->dp_debug.aspect_ratio = aspect_ratio;
  294. goto end;
  295. clear:
  296. pr_debug("clearing debug modes\n");
  297. debug->dp_debug.debug_en = false;
  298. end:
  299. return len;
  300. }
  301. static ssize_t dp_debug_write_edid_modes_mst(struct file *file,
  302. const char __user *user_buff, size_t count, loff_t *ppos)
  303. {
  304. struct dp_debug_private *debug = file->private_data;
  305. struct dp_mst_connector *mst_connector;
  306. char buf[SZ_512];
  307. char *read_buf;
  308. size_t len = 0;
  309. int hdisplay = 0, vdisplay = 0, vrefresh = 0, aspect_ratio = 0;
  310. int con_id = 0, offset = 0, debug_en = 0;
  311. bool in_list = false;
  312. if (!debug)
  313. return -ENODEV;
  314. if (*ppos)
  315. goto end;
  316. len = min_t(size_t, count, SZ_512 - 1);
  317. if (copy_from_user(buf, user_buff, len))
  318. goto end;
  319. buf[len] = '\0';
  320. read_buf = buf;
  321. mutex_lock(&debug->dp_debug.dp_mst_connector_list.lock);
  322. while (sscanf(read_buf, "%d %d %d %d %d %d%n", &debug_en, &con_id,
  323. &hdisplay, &vdisplay, &vrefresh, &aspect_ratio,
  324. &offset) == 6) {
  325. list_for_each_entry(mst_connector,
  326. &debug->dp_debug.dp_mst_connector_list.list,
  327. list) {
  328. if (mst_connector->con_id == con_id) {
  329. in_list = true;
  330. mst_connector->debug_en = (bool) debug_en;
  331. mst_connector->hdisplay = hdisplay;
  332. mst_connector->vdisplay = vdisplay;
  333. mst_connector->vrefresh = vrefresh;
  334. mst_connector->aspect_ratio = aspect_ratio;
  335. }
  336. }
  337. if (!in_list)
  338. pr_debug("dp connector id %d is invalid\n", con_id);
  339. in_list = false;
  340. read_buf += offset;
  341. }
  342. mutex_unlock(&debug->dp_debug.dp_mst_connector_list.lock);
  343. end:
  344. return len;
  345. }
  346. static ssize_t dp_debug_write_mst_con_id(struct file *file,
  347. const char __user *user_buff, size_t count, loff_t *ppos)
  348. {
  349. struct dp_debug_private *debug = file->private_data;
  350. struct dp_mst_connector *mst_connector;
  351. char buf[SZ_32];
  352. size_t len = 0;
  353. int con_id = 0, status;
  354. bool in_list = false;
  355. const int dp_en = BIT(3), hpd_high = BIT(7), hpd_irq = BIT(8);
  356. int vdo = dp_en | hpd_high | hpd_irq;
  357. if (!debug)
  358. return -ENODEV;
  359. if (*ppos)
  360. goto end;
  361. /* Leave room for termination char */
  362. len = min_t(size_t, count, SZ_32 - 1);
  363. if (copy_from_user(buf, user_buff, len))
  364. goto clear;
  365. buf[len] = '\0';
  366. if (sscanf(buf, "%d %d", &con_id, &status) != 2) {
  367. len = 0;
  368. goto end;
  369. }
  370. if (!con_id)
  371. goto clear;
  372. /* Verify that the connector id is for a valid mst connector. */
  373. mutex_lock(&debug->dp_debug.dp_mst_connector_list.lock);
  374. list_for_each_entry(mst_connector,
  375. &debug->dp_debug.dp_mst_connector_list.list, list) {
  376. if (mst_connector->con_id == con_id) {
  377. in_list = true;
  378. debug->mst_con_id = con_id;
  379. mst_connector->state = status;
  380. break;
  381. }
  382. }
  383. mutex_unlock(&debug->dp_debug.dp_mst_connector_list.lock);
  384. if (!in_list)
  385. pr_err("invalid connector id %u\n", con_id);
  386. else if (status != connector_status_unknown) {
  387. debug->dp_debug.mst_hpd_sim = true;
  388. debug->hpd->simulate_attention(debug->hpd, vdo);
  389. }
  390. goto end;
  391. clear:
  392. pr_debug("clearing mst_con_id\n");
  393. debug->mst_con_id = 0;
  394. end:
  395. return len;
  396. }
  397. static ssize_t dp_debug_bw_code_write(struct file *file,
  398. const char __user *user_buff, size_t count, loff_t *ppos)
  399. {
  400. struct dp_debug_private *debug = file->private_data;
  401. char buf[SZ_8];
  402. size_t len = 0;
  403. u32 max_bw_code = 0;
  404. if (!debug)
  405. return -ENODEV;
  406. if (*ppos)
  407. return 0;
  408. /* Leave room for termination char */
  409. len = min_t(size_t, count, SZ_8 - 1);
  410. if (copy_from_user(buf, user_buff, len))
  411. return 0;
  412. buf[len] = '\0';
  413. if (kstrtoint(buf, 10, &max_bw_code) != 0)
  414. return 0;
  415. if (!is_link_rate_valid(max_bw_code)) {
  416. pr_err("Unsupported bw code %d\n", max_bw_code);
  417. return len;
  418. }
  419. debug->panel->max_bw_code = max_bw_code;
  420. pr_debug("max_bw_code: %d\n", max_bw_code);
  421. return len;
  422. }
  423. static ssize_t dp_debug_mst_mode_read(struct file *file,
  424. char __user *user_buff, size_t count, loff_t *ppos)
  425. {
  426. struct dp_debug_private *debug = file->private_data;
  427. char buf[64];
  428. ssize_t len;
  429. len = scnprintf(buf, sizeof(buf),
  430. "mst_mode = %d, mst_state = %d\n",
  431. debug->parser->has_mst,
  432. debug->panel->mst_state);
  433. return simple_read_from_buffer(user_buff, count, ppos, buf, len);
  434. }
  435. static ssize_t dp_debug_mst_mode_write(struct file *file,
  436. const char __user *user_buff, size_t count, loff_t *ppos)
  437. {
  438. struct dp_debug_private *debug = file->private_data;
  439. char buf[SZ_8];
  440. size_t len = 0;
  441. u32 mst_mode = 0;
  442. if (!debug)
  443. return -ENODEV;
  444. if (*ppos)
  445. return 0;
  446. len = min_t(size_t, count, SZ_8 - 1);
  447. if (copy_from_user(buf, user_buff, len))
  448. return 0;
  449. buf[len] = '\0';
  450. if (kstrtoint(buf, 10, &mst_mode) != 0)
  451. return 0;
  452. debug->parser->has_mst = mst_mode ? true : false;
  453. pr_debug("mst_enable: %d\n", mst_mode);
  454. return len;
  455. }
  456. static ssize_t dp_debug_max_pclk_khz_write(struct file *file,
  457. const char __user *user_buff, size_t count, loff_t *ppos)
  458. {
  459. struct dp_debug_private *debug = file->private_data;
  460. char buf[SZ_8];
  461. size_t len = 0;
  462. u32 max_pclk = 0;
  463. if (!debug)
  464. return -ENODEV;
  465. if (*ppos)
  466. return 0;
  467. len = min_t(size_t, count, SZ_8 - 1);
  468. if (copy_from_user(buf, user_buff, len))
  469. return 0;
  470. buf[len] = '\0';
  471. if (kstrtoint(buf, 10, &max_pclk) != 0)
  472. return 0;
  473. if (max_pclk > debug->parser->max_pclk_khz)
  474. pr_err("requested: %d, max_pclk_khz:%d\n", max_pclk,
  475. debug->parser->max_pclk_khz);
  476. else
  477. debug->dp_debug.max_pclk_khz = max_pclk;
  478. pr_debug("max_pclk_khz: %d\n", max_pclk);
  479. return len;
  480. }
  481. static ssize_t dp_debug_max_pclk_khz_read(struct file *file,
  482. char __user *user_buff, size_t count, loff_t *ppos)
  483. {
  484. struct dp_debug_private *debug = file->private_data;
  485. char *buf;
  486. u32 len = 0;
  487. if (!debug)
  488. return -ENODEV;
  489. if (*ppos)
  490. return 0;
  491. buf = kzalloc(SZ_4K, GFP_KERNEL);
  492. if (ZERO_OR_NULL_PTR(buf))
  493. return -ENOMEM;
  494. len += snprintf(buf + len, (SZ_4K - len),
  495. "max_pclk_khz = %d, org: %d\n",
  496. debug->dp_debug.max_pclk_khz,
  497. debug->parser->max_pclk_khz);
  498. if (copy_to_user(user_buff, buf, len)) {
  499. kfree(buf);
  500. return -EFAULT;
  501. }
  502. *ppos += len;
  503. kfree(buf);
  504. return len;
  505. }
  506. static ssize_t dp_debug_mst_sideband_mode_write(struct file *file,
  507. const char __user *user_buff, size_t count, loff_t *ppos)
  508. {
  509. struct dp_debug_private *debug = file->private_data;
  510. char buf[SZ_8];
  511. size_t len = 0;
  512. int mst_sideband_mode = 0;
  513. u32 mst_port_cnt = 0;
  514. if (!debug)
  515. return -ENODEV;
  516. /* Leave room for termination char */
  517. len = min_t(size_t, count, SZ_8 - 1);
  518. if (copy_from_user(buf, user_buff, len))
  519. return -EFAULT;
  520. buf[len] = '\0';
  521. if (sscanf(buf, "%d %u", &mst_sideband_mode, &mst_port_cnt) != 2) {
  522. pr_err("invalid input\n");
  523. return -EINVAL;
  524. }
  525. if (mst_port_cnt > DP_MST_SIM_MAX_PORTS) {
  526. pr_err("port cnt:%d exceeding max:%d\n", mst_port_cnt,
  527. DP_MST_SIM_MAX_PORTS);
  528. return -EINVAL;
  529. }
  530. debug->parser->has_mst_sideband = mst_sideband_mode ? true : false;
  531. debug->dp_debug.mst_port_cnt = mst_port_cnt;
  532. pr_debug("mst_sideband_mode: %d port_cnt:%d\n",
  533. mst_sideband_mode, mst_port_cnt);
  534. return count;
  535. }
  536. static ssize_t dp_debug_widebus_mode_write(struct file *file,
  537. const char __user *user_buff, size_t count, loff_t *ppos)
  538. {
  539. struct dp_debug_private *debug = file->private_data;
  540. char buf[SZ_8];
  541. size_t len = 0;
  542. u32 widebus_mode = 0;
  543. if (!debug || !debug->parser)
  544. return -ENODEV;
  545. if (*ppos)
  546. return 0;
  547. len = min_t(size_t, count, SZ_8 - 1);
  548. if (copy_from_user(buf, user_buff, len))
  549. return -EFAULT;
  550. buf[len] = '\0';
  551. if (kstrtoint(buf, 10, &widebus_mode) != 0)
  552. return -EINVAL;
  553. debug->parser->has_widebus = widebus_mode ? true : false;
  554. pr_debug("widebus_enable: %d\n", widebus_mode);
  555. return len;
  556. }
  557. static ssize_t dp_debug_tpg_write(struct file *file,
  558. const char __user *user_buff, size_t count, loff_t *ppos)
  559. {
  560. struct dp_debug_private *debug = file->private_data;
  561. char buf[SZ_8];
  562. size_t len = 0;
  563. u32 tpg_state = 0;
  564. if (!debug)
  565. return -ENODEV;
  566. if (*ppos)
  567. return 0;
  568. /* Leave room for termination char */
  569. len = min_t(size_t, count, SZ_8 - 1);
  570. if (copy_from_user(buf, user_buff, len))
  571. goto bail;
  572. buf[len] = '\0';
  573. if (kstrtoint(buf, 10, &tpg_state) != 0)
  574. goto bail;
  575. tpg_state &= 0x1;
  576. pr_debug("tpg_state: %d\n", tpg_state);
  577. if (tpg_state == debug->dp_debug.tpg_state)
  578. goto bail;
  579. if (debug->panel)
  580. debug->panel->tpg_config(debug->panel, tpg_state);
  581. debug->dp_debug.tpg_state = tpg_state;
  582. bail:
  583. return len;
  584. }
  585. static ssize_t dp_debug_write_exe_mode(struct file *file,
  586. const char __user *user_buff, size_t count, loff_t *ppos)
  587. {
  588. struct dp_debug_private *debug = file->private_data;
  589. char buf[SZ_32];
  590. size_t len = 0;
  591. if (!debug)
  592. return -ENODEV;
  593. if (*ppos)
  594. return 0;
  595. len = min_t(size_t, count, SZ_32 - 1);
  596. if (copy_from_user(buf, user_buff, len))
  597. goto end;
  598. buf[len] = '\0';
  599. if (sscanf(buf, "%3s", debug->exe_mode) != 1)
  600. goto end;
  601. if (strcmp(debug->exe_mode, "hw") &&
  602. strcmp(debug->exe_mode, "sw") &&
  603. strcmp(debug->exe_mode, "all"))
  604. goto end;
  605. debug->catalog->set_exe_mode(debug->catalog, debug->exe_mode);
  606. end:
  607. return len;
  608. }
  609. static ssize_t dp_debug_read_connected(struct file *file,
  610. char __user *user_buff, size_t count, loff_t *ppos)
  611. {
  612. struct dp_debug_private *debug = file->private_data;
  613. char buf[SZ_8];
  614. u32 len = 0;
  615. if (!debug)
  616. return -ENODEV;
  617. if (*ppos)
  618. return 0;
  619. len += snprintf(buf, SZ_8, "%d\n", debug->hpd->hpd_high);
  620. if (copy_to_user(user_buff, buf, len))
  621. return -EFAULT;
  622. *ppos += len;
  623. return len;
  624. }
  625. static ssize_t dp_debug_write_hdcp(struct file *file,
  626. const char __user *user_buff, size_t count, loff_t *ppos)
  627. {
  628. struct dp_debug_private *debug = file->private_data;
  629. char buf[SZ_8];
  630. size_t len = 0;
  631. int hdcp = 0;
  632. if (!debug)
  633. return -ENODEV;
  634. if (*ppos)
  635. return 0;
  636. /* Leave room for termination char */
  637. len = min_t(size_t, count, SZ_8 - 1);
  638. if (copy_from_user(buf, user_buff, len))
  639. goto end;
  640. buf[len] = '\0';
  641. if (kstrtoint(buf, 10, &hdcp) != 0)
  642. goto end;
  643. debug->dp_debug.hdcp_disabled = !hdcp;
  644. end:
  645. return len;
  646. }
  647. static ssize_t dp_debug_read_hdcp(struct file *file,
  648. char __user *user_buff, size_t count, loff_t *ppos)
  649. {
  650. struct dp_debug_private *debug = file->private_data;
  651. u32 len = 0;
  652. if (!debug)
  653. return -ENODEV;
  654. if (*ppos)
  655. return 0;
  656. len = sizeof(debug->dp_debug.hdcp_status);
  657. if (copy_to_user(user_buff, debug->dp_debug.hdcp_status, len))
  658. return -EFAULT;
  659. *ppos += len;
  660. return len;
  661. }
  662. static int dp_debug_check_buffer_overflow(int rc, int *max_size, int *len)
  663. {
  664. if (rc >= *max_size) {
  665. pr_err("buffer overflow\n");
  666. return -EINVAL;
  667. }
  668. *len += rc;
  669. *max_size = SZ_4K - *len;
  670. return 0;
  671. }
  672. static ssize_t dp_debug_read_edid_modes(struct file *file,
  673. char __user *user_buff, size_t count, loff_t *ppos)
  674. {
  675. struct dp_debug_private *debug = file->private_data;
  676. char *buf;
  677. u32 len = 0, ret = 0, max_size = SZ_4K;
  678. int rc = 0;
  679. struct drm_connector *connector;
  680. struct drm_display_mode *mode;
  681. if (!debug) {
  682. pr_err("invalid data\n");
  683. rc = -ENODEV;
  684. goto error;
  685. }
  686. connector = *debug->connector;
  687. if (!connector) {
  688. pr_err("connector is NULL\n");
  689. rc = -EINVAL;
  690. goto error;
  691. }
  692. if (*ppos)
  693. goto error;
  694. buf = kzalloc(SZ_4K, GFP_KERNEL);
  695. if (ZERO_OR_NULL_PTR(buf)) {
  696. rc = -ENOMEM;
  697. goto error;
  698. }
  699. mutex_lock(&connector->dev->mode_config.mutex);
  700. list_for_each_entry(mode, &connector->modes, head) {
  701. ret = snprintf(buf + len, max_size,
  702. "%s %d %d %d %d %d 0x%x\n",
  703. mode->name, mode->vrefresh, mode->picture_aspect_ratio,
  704. mode->htotal, mode->vtotal, mode->clock, mode->flags);
  705. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  706. break;
  707. }
  708. mutex_unlock(&connector->dev->mode_config.mutex);
  709. if (copy_to_user(user_buff, buf, len)) {
  710. kfree(buf);
  711. rc = -EFAULT;
  712. goto error;
  713. }
  714. *ppos += len;
  715. kfree(buf);
  716. return len;
  717. error:
  718. return rc;
  719. }
  720. static ssize_t dp_debug_read_edid_modes_mst(struct file *file,
  721. char __user *user_buff, size_t count, loff_t *ppos)
  722. {
  723. struct dp_debug_private *debug = file->private_data;
  724. struct dp_mst_connector *mst_connector;
  725. char *buf;
  726. u32 len = 0, ret = 0, max_size = SZ_4K;
  727. int rc = 0;
  728. struct drm_connector *connector;
  729. struct drm_display_mode *mode;
  730. bool in_list = false;
  731. if (!debug) {
  732. pr_err("invalid data\n");
  733. rc = -ENODEV;
  734. goto error;
  735. }
  736. mutex_lock(&debug->dp_debug.dp_mst_connector_list.lock);
  737. list_for_each_entry(mst_connector,
  738. &debug->dp_debug.dp_mst_connector_list.list, list) {
  739. if (mst_connector->con_id == debug->mst_con_id) {
  740. connector = mst_connector->conn;
  741. in_list = true;
  742. }
  743. }
  744. mutex_unlock(&debug->dp_debug.dp_mst_connector_list.lock);
  745. if (!in_list) {
  746. pr_err("connector %u not in mst list\n", debug->mst_con_id);
  747. rc = -EINVAL;
  748. goto error;
  749. }
  750. if (!connector) {
  751. pr_err("connector is NULL\n");
  752. rc = -EINVAL;
  753. goto error;
  754. }
  755. if (*ppos)
  756. goto error;
  757. buf = kzalloc(SZ_4K, GFP_KERNEL);
  758. if (!buf) {
  759. rc = -ENOMEM;
  760. goto error;
  761. }
  762. mutex_lock(&connector->dev->mode_config.mutex);
  763. list_for_each_entry(mode, &connector->modes, head) {
  764. ret = snprintf(buf + len, max_size,
  765. "%s %d %d %d %d %d 0x%x\n",
  766. mode->name, mode->vrefresh,
  767. mode->picture_aspect_ratio, mode->htotal,
  768. mode->vtotal, mode->clock, mode->flags);
  769. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  770. break;
  771. }
  772. mutex_unlock(&connector->dev->mode_config.mutex);
  773. if (copy_to_user(user_buff, buf, len)) {
  774. kfree(buf);
  775. rc = -EFAULT;
  776. goto error;
  777. }
  778. *ppos += len;
  779. kfree(buf);
  780. return len;
  781. error:
  782. return rc;
  783. }
  784. static ssize_t dp_debug_read_mst_con_id(struct file *file,
  785. char __user *user_buff, size_t count, loff_t *ppos)
  786. {
  787. struct dp_debug_private *debug = file->private_data;
  788. char *buf;
  789. u32 len = 0, ret = 0, max_size = SZ_4K;
  790. int rc = 0;
  791. if (!debug) {
  792. pr_err("invalid data\n");
  793. rc = -ENODEV;
  794. goto error;
  795. }
  796. if (*ppos)
  797. goto error;
  798. buf = kzalloc(SZ_4K, GFP_KERNEL);
  799. if (!buf) {
  800. rc = -ENOMEM;
  801. goto error;
  802. }
  803. ret = snprintf(buf, max_size, "%u\n", debug->mst_con_id);
  804. len += ret;
  805. if (copy_to_user(user_buff, buf, len)) {
  806. kfree(buf);
  807. rc = -EFAULT;
  808. goto error;
  809. }
  810. *ppos += len;
  811. kfree(buf);
  812. return len;
  813. error:
  814. return rc;
  815. }
  816. static ssize_t dp_debug_read_mst_conn_info(struct file *file,
  817. char __user *user_buff, size_t count, loff_t *ppos)
  818. {
  819. struct dp_debug_private *debug = file->private_data;
  820. struct dp_mst_connector *mst_connector;
  821. char *buf;
  822. u32 len = 0, ret = 0, max_size = SZ_4K;
  823. int rc = 0;
  824. struct drm_connector *connector;
  825. if (!debug) {
  826. pr_err("invalid data\n");
  827. rc = -ENODEV;
  828. goto error;
  829. }
  830. if (*ppos)
  831. goto error;
  832. buf = kzalloc(SZ_4K, GFP_KERNEL);
  833. if (!buf) {
  834. rc = -ENOMEM;
  835. goto error;
  836. }
  837. mutex_lock(&debug->dp_debug.dp_mst_connector_list.lock);
  838. list_for_each_entry(mst_connector,
  839. &debug->dp_debug.dp_mst_connector_list.list, list) {
  840. /* Do not print info for head node */
  841. if (mst_connector->con_id == -1)
  842. continue;
  843. connector = mst_connector->conn;
  844. if (!connector) {
  845. pr_err("connector for id %d is NULL\n",
  846. mst_connector->con_id);
  847. continue;
  848. }
  849. ret = scnprintf(buf + len, max_size,
  850. "conn name:%s, conn id:%d state:%d\n",
  851. connector->name, connector->base.id,
  852. connector->status);
  853. if (dp_debug_check_buffer_overflow(ret, &max_size, &len))
  854. break;
  855. }
  856. mutex_unlock(&debug->dp_debug.dp_mst_connector_list.lock);
  857. if (copy_to_user(user_buff, buf, len)) {
  858. kfree(buf);
  859. rc = -EFAULT;
  860. goto error;
  861. }
  862. *ppos += len;
  863. kfree(buf);
  864. return len;
  865. error:
  866. return rc;
  867. }
  868. static ssize_t dp_debug_read_info(struct file *file, char __user *user_buff,
  869. size_t count, loff_t *ppos)
  870. {
  871. struct dp_debug_private *debug = file->private_data;
  872. char *buf;
  873. u32 len = 0, rc = 0;
  874. u32 max_size = SZ_4K;
  875. if (!debug)
  876. return -ENODEV;
  877. if (*ppos)
  878. return 0;
  879. buf = kzalloc(SZ_4K, GFP_KERNEL);
  880. if (ZERO_OR_NULL_PTR(buf))
  881. return -ENOMEM;
  882. rc = snprintf(buf + len, max_size, "\tstate=0x%x\n", debug->aux->state);
  883. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  884. goto error;
  885. rc = snprintf(buf + len, max_size, "\tlink_rate=%u\n",
  886. debug->panel->link_info.rate);
  887. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  888. goto error;
  889. rc = snprintf(buf + len, max_size, "\tnum_lanes=%u\n",
  890. debug->panel->link_info.num_lanes);
  891. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  892. goto error;
  893. rc = snprintf(buf + len, max_size, "\tresolution=%dx%d@%dHz\n",
  894. debug->panel->pinfo.h_active,
  895. debug->panel->pinfo.v_active,
  896. debug->panel->pinfo.refresh_rate);
  897. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  898. goto error;
  899. rc = snprintf(buf + len, max_size, "\tpclock=%dKHz\n",
  900. debug->panel->pinfo.pixel_clk_khz);
  901. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  902. goto error;
  903. rc = snprintf(buf + len, max_size, "\tbpp=%d\n",
  904. debug->panel->pinfo.bpp);
  905. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  906. goto error;
  907. /* Link Information */
  908. rc = snprintf(buf + len, max_size, "\ttest_req=%s\n",
  909. dp_link_get_test_name(debug->link->sink_request));
  910. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  911. goto error;
  912. rc = snprintf(buf + len, max_size,
  913. "\tlane_count=%d\n", debug->link->link_params.lane_count);
  914. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  915. goto error;
  916. rc = snprintf(buf + len, max_size,
  917. "\tbw_code=%d\n", debug->link->link_params.bw_code);
  918. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  919. goto error;
  920. rc = snprintf(buf + len, max_size,
  921. "\tv_level=%d\n", debug->link->phy_params.v_level);
  922. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  923. goto error;
  924. rc = snprintf(buf + len, max_size,
  925. "\tp_level=%d\n", debug->link->phy_params.p_level);
  926. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  927. goto error;
  928. if (copy_to_user(user_buff, buf, len))
  929. goto error;
  930. *ppos += len;
  931. kfree(buf);
  932. return len;
  933. error:
  934. kfree(buf);
  935. return -EINVAL;
  936. }
  937. static ssize_t dp_debug_bw_code_read(struct file *file,
  938. char __user *user_buff, size_t count, loff_t *ppos)
  939. {
  940. struct dp_debug_private *debug = file->private_data;
  941. char *buf;
  942. u32 len = 0;
  943. if (!debug)
  944. return -ENODEV;
  945. if (*ppos)
  946. return 0;
  947. buf = kzalloc(SZ_4K, GFP_KERNEL);
  948. if (ZERO_OR_NULL_PTR(buf))
  949. return -ENOMEM;
  950. len += snprintf(buf + len, (SZ_4K - len),
  951. "max_bw_code = %d\n", debug->panel->max_bw_code);
  952. if (copy_to_user(user_buff, buf, len)) {
  953. kfree(buf);
  954. return -EFAULT;
  955. }
  956. *ppos += len;
  957. kfree(buf);
  958. return len;
  959. }
  960. static ssize_t dp_debug_tpg_read(struct file *file,
  961. char __user *user_buff, size_t count, loff_t *ppos)
  962. {
  963. struct dp_debug_private *debug = file->private_data;
  964. char buf[SZ_8];
  965. u32 len = 0;
  966. if (!debug)
  967. return -ENODEV;
  968. if (*ppos)
  969. return 0;
  970. len += snprintf(buf, SZ_8, "%d\n", debug->dp_debug.tpg_state);
  971. if (copy_to_user(user_buff, buf, len))
  972. return -EFAULT;
  973. *ppos += len;
  974. return len;
  975. }
  976. static ssize_t dp_debug_write_hdr(struct file *file,
  977. const char __user *user_buff, size_t count, loff_t *ppos)
  978. {
  979. struct drm_connector *connector;
  980. struct sde_connector *c_conn;
  981. struct sde_connector_state *c_state;
  982. struct dp_debug_private *debug = file->private_data;
  983. char buf[SZ_512];
  984. size_t len = 0;
  985. if (!debug)
  986. return -ENODEV;
  987. if (*ppos)
  988. return 0;
  989. connector = *debug->connector;
  990. c_conn = to_sde_connector(connector);
  991. c_state = to_sde_connector_state(connector->state);
  992. /* Leave room for termination char */
  993. len = min_t(size_t, count, SZ_512 - 1);
  994. if (copy_from_user(buf, user_buff, len))
  995. goto end;
  996. buf[len] = '\0';
  997. if (sscanf(buf, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
  998. &c_state->hdr_meta.hdr_supported,
  999. &c_state->hdr_meta.hdr_state,
  1000. &c_state->hdr_meta.eotf,
  1001. &c_state->hdr_meta.display_primaries_x[0],
  1002. &c_state->hdr_meta.display_primaries_x[1],
  1003. &c_state->hdr_meta.display_primaries_x[2],
  1004. &c_state->hdr_meta.display_primaries_y[0],
  1005. &c_state->hdr_meta.display_primaries_y[1],
  1006. &c_state->hdr_meta.display_primaries_y[2],
  1007. &c_state->hdr_meta.white_point_x,
  1008. &c_state->hdr_meta.white_point_y,
  1009. &c_state->hdr_meta.max_luminance,
  1010. &c_state->hdr_meta.min_luminance,
  1011. &c_state->hdr_meta.max_content_light_level,
  1012. &c_state->hdr_meta.max_average_light_level) != 15) {
  1013. pr_err("invalid input\n");
  1014. len = -EINVAL;
  1015. }
  1016. debug->panel->setup_hdr(debug->panel, &c_state->hdr_meta, false, 0);
  1017. end:
  1018. return len;
  1019. }
  1020. static ssize_t dp_debug_read_hdr(struct file *file,
  1021. char __user *user_buff, size_t count, loff_t *ppos)
  1022. {
  1023. struct dp_debug_private *debug = file->private_data;
  1024. char *buf;
  1025. u32 len = 0, i;
  1026. u32 max_size = SZ_4K;
  1027. int rc = 0;
  1028. struct drm_connector *connector;
  1029. struct sde_connector *c_conn;
  1030. struct sde_connector_state *c_state;
  1031. struct drm_msm_ext_hdr_metadata *hdr;
  1032. if (!debug) {
  1033. pr_err("invalid data\n");
  1034. rc = -ENODEV;
  1035. goto error;
  1036. }
  1037. connector = *debug->connector;
  1038. if (!connector) {
  1039. pr_err("connector is NULL\n");
  1040. rc = -EINVAL;
  1041. goto error;
  1042. }
  1043. if (*ppos)
  1044. goto error;
  1045. buf = kzalloc(SZ_4K, GFP_KERNEL);
  1046. if (ZERO_OR_NULL_PTR(buf)) {
  1047. rc = -ENOMEM;
  1048. goto error;
  1049. }
  1050. c_conn = to_sde_connector(connector);
  1051. c_state = to_sde_connector_state(connector->state);
  1052. hdr = &c_state->hdr_meta;
  1053. rc = snprintf(buf + len, max_size,
  1054. "============SINK HDR PARAMETERS===========\n");
  1055. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1056. goto error;
  1057. rc = snprintf(buf + len, max_size, "eotf = %d\n",
  1058. connector->hdr_eotf);
  1059. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1060. goto error;
  1061. rc = snprintf(buf + len, max_size, "type_one = %d\n",
  1062. connector->hdr_metadata_type_one);
  1063. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1064. goto error;
  1065. rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
  1066. connector->hdr_max_luminance);
  1067. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1068. goto error;
  1069. rc = snprintf(buf + len, max_size, "avg_luminance = %d\n",
  1070. connector->hdr_avg_luminance);
  1071. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1072. goto error;
  1073. rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
  1074. connector->hdr_min_luminance);
  1075. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1076. goto error;
  1077. rc = snprintf(buf + len, max_size,
  1078. "============VIDEO HDR PARAMETERS===========\n");
  1079. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1080. goto error;
  1081. rc = snprintf(buf + len, max_size, "hdr_state = %d\n", hdr->hdr_state);
  1082. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1083. goto error;
  1084. rc = snprintf(buf + len, max_size, "hdr_supported = %d\n",
  1085. hdr->hdr_supported);
  1086. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1087. goto error;
  1088. rc = snprintf(buf + len, max_size, "eotf = %d\n", hdr->eotf);
  1089. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1090. goto error;
  1091. rc = snprintf(buf + len, max_size, "white_point_x = %d\n",
  1092. hdr->white_point_x);
  1093. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1094. goto error;
  1095. rc = snprintf(buf + len, max_size, "white_point_y = %d\n",
  1096. hdr->white_point_y);
  1097. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1098. goto error;
  1099. rc = snprintf(buf + len, max_size, "max_luminance = %d\n",
  1100. hdr->max_luminance);
  1101. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1102. goto error;
  1103. rc = snprintf(buf + len, max_size, "min_luminance = %d\n",
  1104. hdr->min_luminance);
  1105. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1106. goto error;
  1107. rc = snprintf(buf + len, max_size, "max_content_light_level = %d\n",
  1108. hdr->max_content_light_level);
  1109. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1110. goto error;
  1111. rc = snprintf(buf + len, max_size, "min_content_light_level = %d\n",
  1112. hdr->max_average_light_level);
  1113. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1114. goto error;
  1115. for (i = 0; i < HDR_PRIMARIES_COUNT; i++) {
  1116. rc = snprintf(buf + len, max_size, "primaries_x[%d] = %d\n",
  1117. i, hdr->display_primaries_x[i]);
  1118. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1119. goto error;
  1120. rc = snprintf(buf + len, max_size, "primaries_y[%d] = %d\n",
  1121. i, hdr->display_primaries_y[i]);
  1122. if (dp_debug_check_buffer_overflow(rc, &max_size, &len))
  1123. goto error;
  1124. }
  1125. if (copy_to_user(user_buff, buf, len)) {
  1126. kfree(buf);
  1127. rc = -EFAULT;
  1128. goto error;
  1129. }
  1130. *ppos += len;
  1131. kfree(buf);
  1132. return len;
  1133. error:
  1134. return rc;
  1135. }
  1136. static void dp_debug_set_sim_mode(struct dp_debug_private *debug, bool sim)
  1137. {
  1138. if (sim) {
  1139. if (dp_debug_get_edid_buf(debug))
  1140. return;
  1141. if (dp_debug_get_dpcd_buf(debug)) {
  1142. devm_kfree(debug->dev, debug->edid);
  1143. debug->edid = NULL;
  1144. return;
  1145. }
  1146. debug->dp_debug.sim_mode = true;
  1147. debug->aux->set_sim_mode(debug->aux, true,
  1148. debug->edid, debug->dpcd);
  1149. } else {
  1150. debug->aux->abort(debug->aux);
  1151. debug->ctrl->abort(debug->ctrl);
  1152. debug->aux->set_sim_mode(debug->aux, false, NULL, NULL);
  1153. debug->dp_debug.sim_mode = false;
  1154. debug->panel->set_edid(debug->panel, 0);
  1155. if (debug->edid) {
  1156. devm_kfree(debug->dev, debug->edid);
  1157. debug->edid = NULL;
  1158. }
  1159. debug->panel->set_dpcd(debug->panel, 0);
  1160. if (debug->dpcd) {
  1161. devm_kfree(debug->dev, debug->dpcd);
  1162. debug->dpcd = NULL;
  1163. }
  1164. }
  1165. /*
  1166. * print simulation status as this code is executed
  1167. * only while running in debug mode which is manually
  1168. * triggered by a tester or a script.
  1169. */
  1170. pr_info("%s\n", sim ? "[ON]" : "[OFF]");
  1171. }
  1172. static ssize_t dp_debug_write_sim(struct file *file,
  1173. const char __user *user_buff, size_t count, loff_t *ppos)
  1174. {
  1175. struct dp_debug_private *debug = file->private_data;
  1176. char buf[SZ_8];
  1177. size_t len = 0;
  1178. int sim;
  1179. if (!debug)
  1180. return -ENODEV;
  1181. if (*ppos)
  1182. return 0;
  1183. mutex_lock(&debug->lock);
  1184. /* Leave room for termination char */
  1185. len = min_t(size_t, count, SZ_8 - 1);
  1186. if (copy_from_user(buf, user_buff, len))
  1187. goto end;
  1188. buf[len] = '\0';
  1189. if (kstrtoint(buf, 10, &sim) != 0)
  1190. goto end;
  1191. dp_debug_set_sim_mode(debug, sim);
  1192. end:
  1193. mutex_unlock(&debug->lock);
  1194. return len;
  1195. }
  1196. static ssize_t dp_debug_write_attention(struct file *file,
  1197. const char __user *user_buff, size_t count, loff_t *ppos)
  1198. {
  1199. struct dp_debug_private *debug = file->private_data;
  1200. char buf[SZ_8];
  1201. size_t len = 0;
  1202. int vdo;
  1203. if (!debug)
  1204. return -ENODEV;
  1205. if (*ppos)
  1206. return 0;
  1207. /* Leave room for termination char */
  1208. len = min_t(size_t, count, SZ_8 - 1);
  1209. if (copy_from_user(buf, user_buff, len))
  1210. goto end;
  1211. buf[len] = '\0';
  1212. if (kstrtoint(buf, 10, &vdo) != 0)
  1213. goto end;
  1214. debug->hpd->simulate_attention(debug->hpd, vdo);
  1215. end:
  1216. return len;
  1217. }
  1218. static ssize_t dp_debug_write_dump(struct file *file,
  1219. const char __user *user_buff, size_t count, loff_t *ppos)
  1220. {
  1221. struct dp_debug_private *debug = file->private_data;
  1222. char buf[SZ_32];
  1223. size_t len = 0;
  1224. if (!debug)
  1225. return -ENODEV;
  1226. if (*ppos)
  1227. return 0;
  1228. /* Leave room for termination char */
  1229. len = min_t(size_t, count, SZ_32 - 1);
  1230. if (copy_from_user(buf, user_buff, len))
  1231. goto end;
  1232. buf[len] = '\0';
  1233. if (sscanf(buf, "%31s", debug->reg_dump) != 1)
  1234. goto end;
  1235. /* qfprom register dump not supported */
  1236. if (!strcmp(debug->reg_dump, "qfprom_physical"))
  1237. strlcpy(debug->reg_dump, "clear", sizeof(debug->reg_dump));
  1238. end:
  1239. return len;
  1240. }
  1241. static ssize_t dp_debug_read_dump(struct file *file,
  1242. char __user *user_buff, size_t count, loff_t *ppos)
  1243. {
  1244. int rc = 0;
  1245. struct dp_debug_private *debug = file->private_data;
  1246. u8 *buf = NULL;
  1247. u32 len = 0;
  1248. char prefix[SZ_32];
  1249. if (!debug)
  1250. return -ENODEV;
  1251. if (*ppos)
  1252. return 0;
  1253. if (!debug->hpd->hpd_high || !strlen(debug->reg_dump))
  1254. goto end;
  1255. rc = debug->catalog->get_reg_dump(debug->catalog,
  1256. debug->reg_dump, &buf, &len);
  1257. if (rc)
  1258. goto end;
  1259. snprintf(prefix, sizeof(prefix), "%s: ", debug->reg_dump);
  1260. print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_NONE,
  1261. 16, 4, buf, len, false);
  1262. if (copy_to_user(user_buff, buf, len))
  1263. return -EFAULT;
  1264. *ppos += len;
  1265. end:
  1266. return len;
  1267. }
  1268. static const struct file_operations dp_debug_fops = {
  1269. .open = simple_open,
  1270. .read = dp_debug_read_info,
  1271. };
  1272. static const struct file_operations edid_modes_fops = {
  1273. .open = simple_open,
  1274. .read = dp_debug_read_edid_modes,
  1275. .write = dp_debug_write_edid_modes,
  1276. };
  1277. static const struct file_operations edid_modes_mst_fops = {
  1278. .open = simple_open,
  1279. .read = dp_debug_read_edid_modes_mst,
  1280. .write = dp_debug_write_edid_modes_mst,
  1281. };
  1282. static const struct file_operations mst_conn_info_fops = {
  1283. .open = simple_open,
  1284. .read = dp_debug_read_mst_conn_info,
  1285. };
  1286. static const struct file_operations mst_con_id_fops = {
  1287. .open = simple_open,
  1288. .read = dp_debug_read_mst_con_id,
  1289. .write = dp_debug_write_mst_con_id,
  1290. };
  1291. static const struct file_operations hpd_fops = {
  1292. .open = simple_open,
  1293. .write = dp_debug_write_hpd,
  1294. };
  1295. static const struct file_operations edid_fops = {
  1296. .open = simple_open,
  1297. .write = dp_debug_write_edid,
  1298. };
  1299. static const struct file_operations dpcd_fops = {
  1300. .open = simple_open,
  1301. .write = dp_debug_write_dpcd,
  1302. .read = dp_debug_read_dpcd,
  1303. };
  1304. static const struct file_operations connected_fops = {
  1305. .open = simple_open,
  1306. .read = dp_debug_read_connected,
  1307. };
  1308. static const struct file_operations bw_code_fops = {
  1309. .open = simple_open,
  1310. .read = dp_debug_bw_code_read,
  1311. .write = dp_debug_bw_code_write,
  1312. };
  1313. static const struct file_operations exe_mode_fops = {
  1314. .open = simple_open,
  1315. .write = dp_debug_write_exe_mode,
  1316. };
  1317. static const struct file_operations tpg_fops = {
  1318. .open = simple_open,
  1319. .read = dp_debug_tpg_read,
  1320. .write = dp_debug_tpg_write,
  1321. };
  1322. static const struct file_operations hdr_fops = {
  1323. .open = simple_open,
  1324. .write = dp_debug_write_hdr,
  1325. .read = dp_debug_read_hdr,
  1326. };
  1327. static const struct file_operations sim_fops = {
  1328. .open = simple_open,
  1329. .write = dp_debug_write_sim,
  1330. };
  1331. static const struct file_operations attention_fops = {
  1332. .open = simple_open,
  1333. .write = dp_debug_write_attention,
  1334. };
  1335. static const struct file_operations dump_fops = {
  1336. .open = simple_open,
  1337. .write = dp_debug_write_dump,
  1338. .read = dp_debug_read_dump,
  1339. };
  1340. static const struct file_operations mst_mode_fops = {
  1341. .open = simple_open,
  1342. .write = dp_debug_mst_mode_write,
  1343. .read = dp_debug_mst_mode_read,
  1344. };
  1345. static const struct file_operations mst_sideband_mode_fops = {
  1346. .open = simple_open,
  1347. .write = dp_debug_mst_sideband_mode_write,
  1348. };
  1349. static const struct file_operations max_pclk_khz_fops = {
  1350. .open = simple_open,
  1351. .write = dp_debug_max_pclk_khz_write,
  1352. .read = dp_debug_max_pclk_khz_read,
  1353. };
  1354. static const struct file_operations hdcp_fops = {
  1355. .open = simple_open,
  1356. .write = dp_debug_write_hdcp,
  1357. .read = dp_debug_read_hdcp,
  1358. };
  1359. static const struct file_operations widebus_mode_fops = {
  1360. .open = simple_open,
  1361. .write = dp_debug_widebus_mode_write,
  1362. };
  1363. static int dp_debug_init(struct dp_debug *dp_debug)
  1364. {
  1365. int rc = 0;
  1366. struct dp_debug_private *debug = container_of(dp_debug,
  1367. struct dp_debug_private, dp_debug);
  1368. struct dentry *dir, *file;
  1369. dir = debugfs_create_dir(DEBUG_NAME, NULL);
  1370. if (IS_ERR_OR_NULL(dir)) {
  1371. if (!dir)
  1372. rc = -EINVAL;
  1373. else
  1374. rc = PTR_ERR(dir);
  1375. pr_err("[%s] debugfs create dir failed, rc = %d\n",
  1376. DEBUG_NAME, rc);
  1377. goto error;
  1378. }
  1379. debug->root = dir;
  1380. file = debugfs_create_file("dp_debug", 0444, dir,
  1381. debug, &dp_debug_fops);
  1382. if (IS_ERR_OR_NULL(file)) {
  1383. rc = PTR_ERR(file);
  1384. pr_err("[%s] debugfs create file failed, rc=%d\n",
  1385. DEBUG_NAME, rc);
  1386. goto error_remove_dir;
  1387. }
  1388. file = debugfs_create_file("edid_modes", 0644, dir,
  1389. debug, &edid_modes_fops);
  1390. if (IS_ERR_OR_NULL(file)) {
  1391. rc = PTR_ERR(file);
  1392. pr_err("[%s] debugfs create edid_modes failed, rc=%d\n",
  1393. DEBUG_NAME, rc);
  1394. goto error_remove_dir;
  1395. }
  1396. file = debugfs_create_file("edid_modes_mst", 0644, dir,
  1397. debug, &edid_modes_mst_fops);
  1398. if (IS_ERR_OR_NULL(file)) {
  1399. rc = PTR_ERR(file);
  1400. pr_err("[%s] debugfs create edid_modes_mst failed, rc=%d\n",
  1401. DEBUG_NAME, rc);
  1402. goto error_remove_dir;
  1403. }
  1404. file = debugfs_create_file("mst_con_id", 0644, dir,
  1405. debug, &mst_con_id_fops);
  1406. if (IS_ERR_OR_NULL(file)) {
  1407. rc = PTR_ERR(file);
  1408. pr_err("[%s] debugfs create mst_con_id failed, rc=%d\n",
  1409. DEBUG_NAME, rc);
  1410. goto error_remove_dir;
  1411. }
  1412. file = debugfs_create_file("mst_con_info", 0644, dir,
  1413. debug, &mst_conn_info_fops);
  1414. if (IS_ERR_OR_NULL(file)) {
  1415. rc = PTR_ERR(file);
  1416. pr_err("[%s] debugfs create mst_conn_info failed, rc=%d\n",
  1417. DEBUG_NAME, rc);
  1418. goto error_remove_dir;
  1419. }
  1420. file = debugfs_create_file("hpd", 0644, dir,
  1421. debug, &hpd_fops);
  1422. if (IS_ERR_OR_NULL(file)) {
  1423. rc = PTR_ERR(file);
  1424. pr_err("[%s] debugfs hpd failed, rc=%d\n",
  1425. DEBUG_NAME, rc);
  1426. goto error_remove_dir;
  1427. }
  1428. file = debugfs_create_file("connected", 0444, dir,
  1429. debug, &connected_fops);
  1430. if (IS_ERR_OR_NULL(file)) {
  1431. rc = PTR_ERR(file);
  1432. pr_err("[%s] debugfs connected failed, rc=%d\n",
  1433. DEBUG_NAME, rc);
  1434. goto error_remove_dir;
  1435. }
  1436. file = debugfs_create_file("max_bw_code", 0644, dir,
  1437. debug, &bw_code_fops);
  1438. if (IS_ERR_OR_NULL(file)) {
  1439. rc = PTR_ERR(file);
  1440. pr_err("[%s] debugfs max_bw_code failed, rc=%d\n",
  1441. DEBUG_NAME, rc);
  1442. }
  1443. file = debugfs_create_file("exe_mode", 0644, dir,
  1444. debug, &exe_mode_fops);
  1445. if (IS_ERR_OR_NULL(file)) {
  1446. rc = PTR_ERR(file);
  1447. pr_err("[%s] debugfs register failed, rc=%d\n",
  1448. DEBUG_NAME, rc);
  1449. }
  1450. file = debugfs_create_file("edid", 0644, dir,
  1451. debug, &edid_fops);
  1452. if (IS_ERR_OR_NULL(file)) {
  1453. rc = PTR_ERR(file);
  1454. pr_err("[%s] debugfs edid failed, rc=%d\n",
  1455. DEBUG_NAME, rc);
  1456. goto error_remove_dir;
  1457. }
  1458. file = debugfs_create_file("dpcd", 0644, dir,
  1459. debug, &dpcd_fops);
  1460. if (IS_ERR_OR_NULL(file)) {
  1461. rc = PTR_ERR(file);
  1462. pr_err("[%s] debugfs dpcd failed, rc=%d\n",
  1463. DEBUG_NAME, rc);
  1464. goto error_remove_dir;
  1465. }
  1466. file = debugfs_create_file("tpg_ctrl", 0644, dir,
  1467. debug, &tpg_fops);
  1468. if (IS_ERR_OR_NULL(file)) {
  1469. rc = PTR_ERR(file);
  1470. pr_err("[%s] debugfs tpg failed, rc=%d\n",
  1471. DEBUG_NAME, rc);
  1472. goto error_remove_dir;
  1473. }
  1474. file = debugfs_create_file("hdr", 0644, dir,
  1475. debug, &hdr_fops);
  1476. if (IS_ERR_OR_NULL(file)) {
  1477. rc = PTR_ERR(file);
  1478. pr_err("[%s] debugfs hdr failed, rc=%d\n",
  1479. DEBUG_NAME, rc);
  1480. goto error_remove_dir;
  1481. }
  1482. file = debugfs_create_file("sim", 0644, dir,
  1483. debug, &sim_fops);
  1484. if (IS_ERR_OR_NULL(file)) {
  1485. rc = PTR_ERR(file);
  1486. pr_err("[%s] debugfs sim failed, rc=%d\n",
  1487. DEBUG_NAME, rc);
  1488. goto error_remove_dir;
  1489. }
  1490. file = debugfs_create_file("attention", 0644, dir,
  1491. debug, &attention_fops);
  1492. if (IS_ERR_OR_NULL(file)) {
  1493. rc = PTR_ERR(file);
  1494. pr_err("[%s] debugfs attention failed, rc=%d\n",
  1495. DEBUG_NAME, rc);
  1496. goto error_remove_dir;
  1497. }
  1498. file = debugfs_create_file("dump", 0644, dir,
  1499. debug, &dump_fops);
  1500. if (IS_ERR_OR_NULL(file)) {
  1501. rc = PTR_ERR(file);
  1502. pr_err("[%s] debugfs dump failed, rc=%d\n",
  1503. DEBUG_NAME, rc);
  1504. goto error_remove_dir;
  1505. }
  1506. file = debugfs_create_file("mst_mode", 0644, dir,
  1507. debug, &mst_mode_fops);
  1508. if (IS_ERR_OR_NULL(file)) {
  1509. rc = PTR_ERR(file);
  1510. pr_err("[%s] debugfs max_bw_code failed, rc=%d\n",
  1511. DEBUG_NAME, rc);
  1512. goto error_remove_dir;
  1513. }
  1514. file = debugfs_create_file("mst_sideband_mode", 0644, dir,
  1515. debug, &mst_sideband_mode_fops);
  1516. if (IS_ERR_OR_NULL(file)) {
  1517. rc = PTR_ERR(file);
  1518. pr_err("[%s] debugfs max_bw_code failed, rc=%d\n",
  1519. DEBUG_NAME, rc);
  1520. goto error_remove_dir;
  1521. }
  1522. file = debugfs_create_file("max_pclk_khz", 0644, dir,
  1523. debug, &max_pclk_khz_fops);
  1524. if (IS_ERR_OR_NULL(file)) {
  1525. rc = PTR_ERR(file);
  1526. pr_err("[%s] debugfs max_pclk_khz failed, rc=%d\n",
  1527. DEBUG_NAME, rc);
  1528. goto error_remove_dir;
  1529. }
  1530. file = debugfs_create_bool("force_encryption", 0644, dir,
  1531. &debug->dp_debug.force_encryption);
  1532. if (IS_ERR_OR_NULL(file)) {
  1533. rc = PTR_ERR(file);
  1534. pr_err("[%s] debugfs force_encryption failed, rc=%d\n",
  1535. DEBUG_NAME, rc);
  1536. goto error_remove_dir;
  1537. }
  1538. file = debugfs_create_file("hdcp", 0644, dir,
  1539. debug, &hdcp_fops);
  1540. if (IS_ERR_OR_NULL(file)) {
  1541. rc = PTR_ERR(file);
  1542. pr_err("[%s] debugfs hdcp failed, rc=%d\n",
  1543. DEBUG_NAME, rc);
  1544. goto error_remove_dir;
  1545. }
  1546. file = debugfs_create_bool("hdcp_wait_sink_sync", 0644, dir,
  1547. &debug->dp_debug.hdcp_wait_sink_sync);
  1548. if (IS_ERR_OR_NULL(file)) {
  1549. rc = PTR_ERR(file);
  1550. pr_err("[%s] debugfs hdcp_wait_sink_sync failed, rc=%d\n",
  1551. DEBUG_NAME, rc);
  1552. goto error_remove_dir;
  1553. }
  1554. file = debugfs_create_bool("dsc_feature_enable", 0644, dir,
  1555. &debug->parser->dsc_feature_enable);
  1556. if (IS_ERR_OR_NULL(file)) {
  1557. rc = PTR_ERR(file);
  1558. pr_err("[%s] debugfs dsc_feature failed, rc=%d\n",
  1559. DEBUG_NAME, rc);
  1560. }
  1561. file = debugfs_create_bool("fec_feature_enable", 0644, dir,
  1562. &debug->parser->fec_feature_enable);
  1563. if (IS_ERR_OR_NULL(file)) {
  1564. rc = PTR_ERR(file);
  1565. pr_err("[%s] debugfs fec_feature_enable failed, rc=%d\n",
  1566. DEBUG_NAME, rc);
  1567. }
  1568. file = debugfs_create_file("widebus_mode", 0644, dir,
  1569. debug, &widebus_mode_fops);
  1570. if (IS_ERR_OR_NULL(file)) {
  1571. rc = PTR_ERR(file);
  1572. pr_err("[%s] debugfs widebus failed, rc=%d\n",
  1573. DEBUG_NAME, rc);
  1574. }
  1575. file = debugfs_create_u32("max_lclk_khz", 0644, dir,
  1576. &debug->parser->max_lclk_khz);
  1577. if (IS_ERR_OR_NULL(file)) {
  1578. rc = PTR_ERR(file);
  1579. pr_err("[%s] debugfs max_lclk_khz failed, rc=%d\n",
  1580. DEBUG_NAME, rc);
  1581. }
  1582. return 0;
  1583. error_remove_dir:
  1584. if (!file)
  1585. rc = -EINVAL;
  1586. debugfs_remove_recursive(dir);
  1587. error:
  1588. return rc;
  1589. }
  1590. u8 *dp_debug_get_edid(struct dp_debug *dp_debug)
  1591. {
  1592. struct dp_debug_private *debug;
  1593. if (!dp_debug)
  1594. return NULL;
  1595. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1596. return debug->edid;
  1597. }
  1598. static void dp_debug_abort(struct dp_debug *dp_debug)
  1599. {
  1600. struct dp_debug_private *debug;
  1601. if (!dp_debug)
  1602. return;
  1603. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1604. mutex_lock(&debug->lock);
  1605. dp_debug_set_sim_mode(debug, false);
  1606. mutex_unlock(&debug->lock);
  1607. }
  1608. struct dp_debug *dp_debug_get(struct dp_debug_in *in)
  1609. {
  1610. int rc = 0;
  1611. struct dp_debug_private *debug;
  1612. struct dp_debug *dp_debug;
  1613. if (!in->dev || !in->panel || !in->hpd || !in->link ||
  1614. !in->catalog || !in->ctrl) {
  1615. pr_err("invalid input\n");
  1616. rc = -EINVAL;
  1617. goto error;
  1618. }
  1619. debug = devm_kzalloc(in->dev, sizeof(*debug), GFP_KERNEL);
  1620. if (!debug) {
  1621. rc = -ENOMEM;
  1622. goto error;
  1623. }
  1624. debug->dp_debug.debug_en = false;
  1625. debug->hpd = in->hpd;
  1626. debug->link = in->link;
  1627. debug->panel = in->panel;
  1628. debug->aux = in->aux;
  1629. debug->dev = in->dev;
  1630. debug->connector = in->connector;
  1631. debug->catalog = in->catalog;
  1632. debug->parser = in->parser;
  1633. debug->ctrl = in->ctrl;
  1634. dp_debug = &debug->dp_debug;
  1635. dp_debug->vdisplay = 0;
  1636. dp_debug->hdisplay = 0;
  1637. dp_debug->vrefresh = 0;
  1638. mutex_init(&debug->lock);
  1639. rc = dp_debug_init(dp_debug);
  1640. if (rc) {
  1641. devm_kfree(in->dev, debug);
  1642. goto error;
  1643. }
  1644. dp_debug->get_edid = dp_debug_get_edid;
  1645. dp_debug->abort = dp_debug_abort;
  1646. INIT_LIST_HEAD(&dp_debug->dp_mst_connector_list.list);
  1647. /*
  1648. * Do not associate the head of the list with any connector in order to
  1649. * maintain backwards compatibility with the SST use case.
  1650. */
  1651. dp_debug->dp_mst_connector_list.con_id = -1;
  1652. dp_debug->dp_mst_connector_list.conn = NULL;
  1653. dp_debug->dp_mst_connector_list.debug_en = false;
  1654. dp_debug->max_pclk_khz = debug->parser->max_pclk_khz;
  1655. return dp_debug;
  1656. error:
  1657. return ERR_PTR(rc);
  1658. }
  1659. static int dp_debug_deinit(struct dp_debug *dp_debug)
  1660. {
  1661. struct dp_debug_private *debug;
  1662. if (!dp_debug)
  1663. return -EINVAL;
  1664. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1665. debugfs_remove_recursive(debug->root);
  1666. return 0;
  1667. }
  1668. void dp_debug_put(struct dp_debug *dp_debug)
  1669. {
  1670. struct dp_debug_private *debug;
  1671. if (!dp_debug)
  1672. return;
  1673. debug = container_of(dp_debug, struct dp_debug_private, dp_debug);
  1674. dp_debug_deinit(dp_debug);
  1675. mutex_destroy(&debug->lock);
  1676. if (debug->edid)
  1677. devm_kfree(debug->dev, debug->edid);
  1678. if (debug->dpcd)
  1679. devm_kfree(debug->dev, debug->dpcd);
  1680. devm_kfree(debug->dev, debug);
  1681. }