dp_debug.c 54 KB

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