dp_debug.c 55 KB

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