dp_debug.c 54 KB

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