dp_debug.c 55 KB

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