dp_debug.c 51 KB

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