dp_debug.c 48 KB

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