dp_debug.c 57 KB

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