dp_debug.c 57 KB

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