dp_debug.c 55 KB

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