dp_debug.c 54 KB

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