dp_debug.c 47 KB

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