dp_debug.c 57 KB

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