dp_debug.c 50 KB

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